Phoenix.pm: Net::Telnet

Scott Walters scott at illogics.org
Wed Jan 14 17:26:19 CST 2004


There is an example of raw sockets on phoenix.pm.org website,
but IO::Socket::INET is about the right level of abstraction for
what you're doing. Clearly Net::Telnet is too much of the wrong
abstraction. Raw sockets are usually too little abstraction.

>From the man page:

              $sock = IO::Socket::INET->new(PeerAddr => 'www.perl.org',
                                            PeerPort => '80',
                                            Proto    => 'tcp');

You can then print to $sock, $sock->print("foo!\n"), read from it,
read $sock, my $buffer, 8192, read lines from it, my $line = readline $sock,
and so on, just like a normal IO::Handle. 

Hope this helps!
-scott

On  0, johngnub at cox.net wrote:
> 
> The cmd method will hold data till the next prompt is found; So the distance of a cmd is the measure of prompt to prompt. 
> 
> If you encounter a nasty prompt try this;
> Issue a cmd to set the prompt right away.
>  @lines = $tango->cmd("PS1='foo';stty kill '^U';export TERM=vt100") 
> 
> Now you can set the prompt to 'foo'
> 
> Prompt  => '/foo/'o'
> 
> Or from the perldoc Net::Telnet:
> 
> " Use a combination of "print()" and "waitfor()" as an
> alternative to "login()" or "cmd()" when they don't 
> what you want. 
> 
> EXAMPLE, note the '/ is a gregex...
> 
> $t->waitfor('/continue:.*$/');
> $t->print("");
> 
> Examples on request...
> > 
> > From: Matt Alexander <m at pdxlug.org>
> > Date: 2004/01/14 Wed AM 10:06:56 EST
> > To: PHXPERL <phoenix-pm-list at happyfunball.pm.org>
> > Subject: Phoenix.pm: Net::Telnet
> > 
> > I'm trying to use Net::Telnet to connect to a device that simply outputs
> > data after a connection is made.  There's no prompt and there's no
> > indication of when it's done sending data, however I know that after about
> > 10 seconds that I should have received all the data that was available.  I
> > then want to save all the output from this device to a log file.
> > 
> > I think the problem with my script is that it's looking for a prompt from
> > the device.  I've tried setting Prompt => undef and Prompt => "", but
> > these both generate warnings and I never retrieve any data.
> > 
> > Any suggestions?
> > Thanks,
> > ~M
> > 
> 



More information about the Phoenix-pm mailing list