Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Net::Telnet blocks

by kp2a (Sexton)
on Jul 18, 2010 at 18:21 UTC ( #850169=perlquestion: print w/ replies, xml ) Need Help??
kp2a has asked for the wisdom of the Perl Monks concerning the following question:

On log in Net::Telnet blocks until specified timeout expires even when login is successful. For example if I specify timeout at 5 years, $telnet->login('admin',$password); will block for 5 years eventhough the login required only milliseconds.

I have thousands to things to telnet to with the result if I set $telnet->timeout() too high my task will take forever, if too low many slow remotes will timeout even though they are on line.

Seems to me proper design would be for telnet->login('admin',$password); to return as soon as login is complete.

Is there a work around or alternate perl telnet to use?

TIA

Comment on Net::Telnet blocks
Re: Net::Telnet blocks
by BrowserUk (Pope) on Jul 18, 2010 at 18:34 UTC

    Did you read this bit in the pod?:

    The methods login() and cmd() use the prompt setting in the object to determine when a login or remote command is complete. Those methods will fail with a time-out if you don't set the prompt correctly.

    Use a combination of print() and waitfor() as an alternative to login() or cmd() when they don't do what you want.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
        tried $telnet->print and $telnet>waitfor rather that $telnet->login

        same results: sucessful login but blocked for timeout seconds

        while playing with pompts I got this message which never appeared before as I had always had the correct prompt

        This indicates to me that the block until timeout has nothing to do with prompt matching:

        error => telnet: 10.100.176.104 pattern match timed-out
        

        kp2a:

        I just tried it out, and had a similar problem. Using the following code, I tried to connect to a local box:

        #!/usr/bin/perl use strict; use warnings; use Net::Telnet; my @lines; my $t = new Net::Telnet( Timeout=>10, Prompt=>'/# $/', Dump_Log=>'NetTelnet_x.log' ); $t->open("192.168.4.190"); $t->login("foo", undef); @lines = $t->cmd("ls"); print @lines;

        It was hanging on the login, as you described. When it finally timed out, I got the message:

        timed-out waiting for password prompt at ./NetTelnet_x.pl line 13

        Well, my local box doesn't have a password on the foo account[1], so it never prompts for password. I just changed the login line to read:

        $t->cmd("foo");

        and it started to work. Perhaps you have the same problem? (I notice that you don't quote the error message anywhere, so I can't tell. The one error message you *did* give was a match timeout from when you were playing with regular expressions.)

        You might try logging in step by step with the cmd() function and verify that the login process is working as you expect. Then you can fix the login() call if you find a surprise.

        ...roboticus

        Notes:

        [1] I don't run Telnet servers (except for the few minutes for this test), so 733t h@X0r2[1] need not get their hopes up...

        [1] Synonym for "script kiddie".

Re: Net::Telnet blocks
by roboticus (Canon) on Jul 19, 2010 at 02:32 UTC

    kp2a:

    You're far too patient. If I had that problem, I would have asked for help about five years ago.... ;^)

    ...roboticus

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://850169]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-11-28 05:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (193 votes), past polls