Opening a Telnet session

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
icarpenter
Forum Commoner
Posts: 84
Joined: Mon Mar 07, 2005 8:12 am
Location: Kent, England

Opening a Telnet session

Post by icarpenter »

Hi I have a peice of kit on my lan that has telnet capabilitys...I would like to open a telnet session, input username and password data, run a system command then extract some information information and then print...

I have tried using fsock...to no avail

Code: Select all

$fp = fsockopen('10.0.0.1', 23);

while ($line = fread($fp, 23))
{
  echo $line;
}
fclose($fp);
Has anyone had any success doing this kind of thing beore...

all i get back is ÿûÿý

Thanks Ian
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

should use SSL instead of telnet, but that's a different topic.

Anyway - from one of the comments on fsockopen in the manual:
http://cvs.adfinis.ch/cvs.php/phpStream ... .class.php
User avatar
icarpenter
Forum Commoner
Posts: 84
Joined: Mon Mar 07, 2005 8:12 am
Location: Kent, England

Post by icarpenter »

Still no Joy.

I triedn this that was on PHP.net...

Code: Select all

# This is the difficult part, the Telnet header
$header1=chr(0xFF).chr(0xFB).chr(0x1F).chr(0xFF).chr(0xFB).
chr(0x20).chr(0xFF).chr(0xFB).chr(0x18).chr(0xFF).chr(0xFB).
chr(0x27).chr(0xFF).chr(0xFD).chr(0x01).chr(0xFF).chr(0xFB).
chr(0x03).chr(0xFF).chr(0xFD).chr(0x03).chr(0xFF).chr(0xFC).
chr(0x23).chr(0xFF).chr(0xFC).chr(0x24).chr(0xFF).chr(0xFA).
chr(0x1F).chr(0x00).chr(0x50).chr(0x00).chr(0x18).chr(0xFF).
chr(0xF0).chr(0xFF).chr(0xFA).chr(0x20).chr(0x00).chr(0x33).
chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0x2C).chr(0x33).
chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0xFF).chr(0xF0).
chr(0xFF).chr(0xFA).chr(0x27).chr(0x00).chr(0xFF).chr(0xF0).
chr(0xFF).chr(0xFA).chr(0x18).chr(0x00).chr(0x58).chr(0x54).
chr(0x45).chr(0x52).chr(0x4D).chr(0xFF).chr(0xF0);
$header2=chr(0xFF).chr(0xFC).chr(0x01).chr(0xFF).chr(0xFC).
chr(0x22).chr(0xFF).chr(0xFE).chr(0x05).chr(0xFF).chr(0xFC).chr(0x21);

# connecting
$fp=fsockopen("10.0.0.1",23);

# sending the Telnet header
fputs($fp,$header1);
usleep(125000);
fputs($fp,$header2);
usleep(125000);

# show the output
do
{
   @$output.=fread($fp, 80);    // read line by line, or at least small chunks
   $stat=socket_get_status($fp);
}
while($stat["unread_bytes"]);

$output = str_replace("\n", "<br>", $output);
echo $output;
fclose($fp);
but this just returns a load of junk...ÿûÿýÿþÿþ ÿþÿþ'ÿüÿû

Can anyone tel me where I might be going wrong?

Thank Ian
Post Reply