Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Net::Telnet timed out when logging in

by poolboi (Acolyte)
on Apr 17, 2008 at 09:15 UTC ( [id://681086]=perlquestion: print w/replies, xml ) Need Help??

poolboi has asked for the wisdom of the Perl Monks concerning the following question:

hi all,
i got time out at my login line of my script
any ideas why this is happening?
i'm on perl 5.10 and on windows XP
it must be te absence of the prompt,
but the problem is i got no idea where to get the prompt
pls help
use Net::Telnet; my $telnet3; $telnet3 = new Net::Telnet(timeout => 10, Errmode => 'die'); $telnet3->open('ip_address'); $telnet3->login('username', 'password'); @lines = $telnet3->cmd("who"); open(FILE, ">file.txt"); print FILE ("@lines\n"); print("logged in to the device.\n");

Replies are listed 'Best First'.
Re: Net::Telnet timed out when logging in
by apl (Monsignor) on Apr 17, 2008 at 09:48 UTC
    You're not testing the error returns on the open or login. Do so, and display any errors. That will give you an idea of where the problem is.

    Non-perl comment: did you try pinging the address? Did you manually logon to that box with the specified ID and password?

Re: Net::Telnet timed out when logging in
by regexes (Hermit) on Apr 17, 2008 at 12:29 UTC
    Hello!

    Update: additional info to glide's post below...

    See in the Net::Telnet documentation about the last_prompt and dump_log methods.

    I like to set my own prompt. That way I always know what I should expect. As mentioned in this node Re: Net::Telent - How to get the prompt displayed after login using telnet?...

    To see what the prompt is, use the last_prompt method.
    $string = $obj->last_prompt; $prev = $obj->last_prompt($string);
    To set the prompt to your choosing...
    $host->login( $username, $password ); my $prompt = "_MYPROMPT_"; $host->prompt("/$prompt\$/"); $host->cmd("prompt = $prompt");
    Since I don't exactly what you're doing... you might also want to take a look in the documentation under the Connecting to a Remote MS-Windows Machine section.

    Hope it helps..

    regexes


    -------------------------
    Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan "press on" has solved and always will solve the problems of the human race.
    -- Calvin Coolidge, 30th President of the USA.
Re: Net::Telnet timed out when logging in
by glide (Pilgrim) on Apr 17, 2008 at 10:11 UTC
    Hi,

    Normally, for the login process, you have to rewrite procedure. And for that you have to use the something like ..

    $telnet->waitfor( -match => qr{ogin} ); $telnet->print($user); $telnet->waitfor( -match => qr{assword} ); $telnet->print($password);
    and to test the solution, create log file of the telnet with
    $telnet->input_log($log_file); $telnet->dump_log($dump_file);
Re: Net::Telnet timed out when logging in
by poolboi (Acolyte) on Apr 18, 2008 at 02:27 UTC
    hi guys, alright i've managed to use glide's code to work apparently when i use login(), i can't can't to let it work 'cos of i need a prompt which i dunno what it is for windows XP below is my latest code:
    #!/perl/bin/perl use strict; use Net::Telnet(); my $telnet; $telnet = new Net::Telnet ( Timeout=>10, Errmode=> 'return'); $telnet->open('ip_address')or die "failed to connect:$!"; $telnet->waitfor( -match => qr{ogin} ); $telnet->print("username"); $telnet->waitfor( -match => qr{assword} ); $telnet->print("password"); $telnet->input_log("C:\\log.txt"); $telnet->dump_log("c:\\dump.txt"); print("login successful");
    apparantly no errors is out and it prints login successful.
    but the dump_log and input_log doesn't seem to contain any information so i'm not too sure if connection to telnet is made yet.
    about what i'm doing i need to connect to SQL database with another proprietary database.
    and this proprietary database is in a switch which i need to telnet into.
    it's all sorta like a automation thing that i need to help my colleges do for easy documentation.
    so now i need to try the first step and that's to establish a connection with telnet..
    so how do i know if it's working? hope my code is correct..pls help? thanks
      Hmmm... what prompt do you receive when you log in using a telnet client from the command line, i.e. without using perl?

      regexes
        alright the prompt i get is as such below
        Trying 010200016058....Open ENTER USERNAME <
        after i type in my username
        i get
        ENTER PASSWORD <
        i'm telneting into a proprietary swtich which makes things really difficult
      hi guys, alright i've managed to use glide's code to work apparently when i use login(), i can't can't to let it work 'cos of i need a prompt which i dunno what it is for windows XP below is my latest code:
      #!/perl/bin/perl use strict; use Net::Telnet(); my $telnet; $telnet = new Net::Telnet ( Timeout=>10, Errmode=> 'return'); $telnet->open('ip_address')or die "failed to connect:$!"; $telnet->waitfor( -match => qr{ogin} ); $telnet->print("username"); $telnet->waitfor( -match => qr{assword} ); $telnet->print("password"); $telnet->input_log("C:\\log.txt"); $telnet->dump_log("c:\\dump.txt"); print("login successful");
      apparantly no errors is out and it prints login successful.
      but the dump_log and input_log doesn't seem to contain any information so i'm not too sure if connection to telnet is made yet.
      about what i'm doing i need to connect to SQL database with another proprietary database.
      and this proprietary database is in a switch which i need to telnet into.
      it's all sorta like a automation thing that i need to help my colleges do for easy documentation.
      so now i need to try the first step and that's to establish a connection with telnet..
      so how do i know if it's working? hope my code is correct..pls help? thanks

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://681086]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-25 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found