468,770 Members | 2,247 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,770 developers. It's quick & easy.

telnet problem with PHP

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,
Andrea.

Dec 22 '05 #1
2 2787
On Thu, 22 Dec 2005 23:50:22 +0100, "_andrea.l"
<an******************@libero.it> wrote:
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.


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 :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Dec 22 '05 #2
_andrea.l wrote:
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? <snip> The program don't exit from while...
... because the telnet don't give feof.
Hoh can I do?


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:
http://groups.google.com/group/comp....ffcd16c5b5f02f
and modify to your taste.

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Dec 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Yannick Turgeon | last post: by
4 posts views Thread by Donnal Walter | last post: by
2 posts views Thread by john brown | last post: by
2 posts views Thread by eight02645999 | last post: by
17 posts views Thread by ravimath | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.