0

using fsockopen, fwrite & fegts to communicate with my account on a remote server over telnet using the following code:

$ip = "*hosts*";
$user = "*username*";
$pass = "*password*";

$fp = fsockopen($ip, 23, $errno, $errstr, 30);
if (!$fp) 
{
    echo "$errstr ($errno)<br />\n";
    exit;
    $utilitiesObj->hardFlush();
} 
else 
{

    echo "<br >We can connect";
    echo "<br >Sending user";

    $retFromFwrite = fwrite($fp,"$user\n");
    echo "<br >ret: ".$retFromFwrite;

        $line =  fgets($fp, 1024);
        echo "<br >line: ".$line;

    echo "<br >Complete";

}
fclose ($fp);

The output I get from the above is:

<br >We can connect<br >Sending user<br >ret: 8<br >line: ÿý%<br >Complete

Any ideas why I get the strange chars? When I login direct through a terminal this is that I get on the screen:

login: *username*
Password:

Thanks in advance.

Dave F
  • 180
  • 1
  • 1
  • 8
  • 1
    Since you're doing raw telnet, you have to expect to get telnet control sequences. – Marc B Nov 20 '13 at 16:37
  • Many thanks for your response Marc B. I tried adding a while loop to see if the response is buried in other lines but I still get the same output (ie the wierd chars). – Dave F Nov 20 '13 at 17:33

0 Answers0