Hello
This is my first post, I just purchased Kevin Yank’s book and it is excellent, I hope this forum rocks too!
I am trying to make a telnet session using fsockopen. Below is the script
It is a cisco switch, the ip is 10.100.102.3 (the pc running the code is on the same network, and a normal telnet session from the shell works)
I see on the screen the following :
connected
23
End.
and when I on purpose change the ip to a non existant device I see
not connected
23
End.
So, I think the connection is established when the IP is real and is not established when the ip is not real.
But the codes after echo "connected\r
"; do not seem to work. I get nothing on the screen, the hostname is not changed either.
What am I doing wrong?
<?php
$cfgPort = "23"; //port, 22 if SSH
$cfgTimeOut = "5";
$cfgServer ="10.100.102.3";
$f=fsockopen("$cfgServer",$cfgPort,$cfgTimeOut);
if (!$f)
{
echo "<pre>";
echo "not connected\\r\
";
}
else
{
echo "<pre>";
echo "connected\\r\
";
echo fgets($f, 1024);
// log in
fwrite($f,"cisco\\r\
");
fwrite($f,"enable\\r\
");
fwrite($f,"password\\r\
");
// change hostname
fwrite($f,"config t\\r\
");
fwrite($f,"hostname testhostname\\r\
");
fwrite($f,"exit\\r\
");
// close connection
fclose($f);
}
echo "$cfgPort\\r\
";
echo "End.\\r\
";
?>
Thanks