Connecting Tech Pros Worldwide Help | Site Map

telnet problem with PHP

 
LinkBack Thread Tools Search this Thread
  #1  
Old December 22nd, 2005, 09:55 PM
_andrea.l
Guest
 
Posts: n/a
Default 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.




  #2  
Old December 22nd, 2005, 10:15 PM
Andy Hassall
Guest
 
Posts: n/a
Default Re: telnet problem with PHP

On Thu, 22 Dec 2005 23:50:22 +0100, "_andrea.l"
<andrea.lorizANTISPAM@libero.it> wrote:
[color=blue]
>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.[/color]

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 :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
  #3  
Old December 23rd, 2005, 10:55 AM
Pedro Graca
Guest
 
Posts: n/a
Default Re: telnet problem with PHP

_andrea.l wrote:[color=blue]
> 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?[/color]
<snip>[color=blue]
> The program don't exit from while...
> ... because the telnet don't give feof.
> Hoh can I do?[/color]

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!
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.