kloon_za
06-12-2008, 01:58 AM
Im trying to use php to connect to telnet server and run a command and echo it to screen. currently my code looks like this:
$fp = fsockopen("public-route-server.is.co.za", 23);
if(!$fp) {
echo "Failed to connect to local route server.";
} else {
while($buf=fgets($fp)) {
echo $buf."<br>";
}
fwrite($fp, "show ip bgp");
while($buf=fgets($fp)) {
echo $buf."<br>";
}
}
the first while is for the welcome message, and then it must write command and read the results. But for some reason, the script hangs at the first while, anybody perhaps know why?
$fp = fsockopen("public-route-server.is.co.za", 23);
if(!$fp) {
echo "Failed to connect to local route server.";
} else {
while($buf=fgets($fp)) {
echo $buf."<br>";
}
fwrite($fp, "show ip bgp");
while($buf=fgets($fp)) {
echo $buf."<br>";
}
}
the first while is for the welcome message, and then it must write command and read the results. But for some reason, the script hangs at the first while, anybody perhaps know why?