telnet problem with PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm writing a little script for reading information from a router by telnet.
I have a problem

How give a comand and get the answer more times?
I means:

 $usenet = fsockopen($cfgServer, $cfgPort, &$errno, &$errstr, $cfgTimeOut);
 fwrite ($usenet, "show interface description\r\n\n");
while (!feof($usenet))
$r1=fgets($usenet, 1000)."<BR>\n";

The program don't exit from while...
... because the telnet don't give feof.
Hoh can I do?

Thank you in advance,

Re: telnet problem with PHP

On Thu, 22 Dec 2005 23:50:22 +0100, "_andrea.l"

Quoted text here. Click to load it

 Are you expecting the device to drop the connection after one command? Or do
you need to send some sort of "exit" command after the "show interface
description" command?

 Otherwise you need to find some sort of unique text that indicates the end of
the output, and use that to stop your while loop.

Andy Hassall :: :: :: disk and FTP usage analysis tool

Re: telnet problem with PHP

_andrea.l wrote:
Quoted text here. Click to load it
Quoted text here. Click to load it

When you telnet to the router 'by hand', how do you know the router has
finished the answer and is ready for more?

You have to make your script follow the same rules.

A long time ago I did a script that telnets to a POP3 server.

Have a look:
and modify to your taste.

Mail to my "From:" address is readable by all at
== ** ## !! ------------------------------------------------ !! ## ** ==
may bypass my spam filter. If it does, I may reply from another address!

Site Timeline