Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Telnet to 1 router through another router

by cpprather (Initiate)
on May 28, 2014 at 14:52 UTC ( [id://1087662]=perlquestion: print w/replies, xml ) Need Help??

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

My perl script times out when I try to telnet to another router/switch from a router. I am able to successfully telnet to the first router. I'm able to set the terminal length and width to 0. I'm able to send the command "telnet 10.0.0.1" and see in my dump_log and input_log that the program gets to the next device prompt which is /username: $/. For the life of me, I cannot get Perl to send my username. I've used print commands to no avail. I've used waitfor to specify the username prompt. I've used the prompt command as well but nothing works. I can attach my code but here are the contents of my dump_log and input_log first:

output_log (truncated): < 0x00000: 54 72 79 69 6e 67 20 37 33 2e 31 39 2e 32 33 37 Trying +x.x.x.x < 0x00010: 2e 35 2e 2e 2e 0d 0d 0a .x..... +. < 0x00000: 20 55 73 65 20 63 6f 6e 66 69 67 75 72 65 64 20 Use co +nfigured < 0x00010: 73 6f 75 72 63 65 20 69 6e 74 65 72 66 61 63 65 source +interface < 0x00020: 28 4c 6f 6f 70 62 61 63 6b 30 29 2e 0d 0d 0a (Loopba +ck0).... < 0x00000: 20 55 73 65 20 36 38 2e 38 37 2e 32 35 33 2e 34 Use x. +x.x.x < 0x00010: 20 61 73 20 6c 6f 63 61 6c 20 61 64 64 72 65 73 as loc +al addres < 0x00020: 73 2e 0d 0d 0a s.... < 0x00000: 43 6f 6e 6e 65 63 74 65 64 20 74 6f 20 37 33 2e Connect +ed to x. < 0x00010: 31 39 2e 32 33 37 2e 35 2e 0d 0d 0a 45 73 63 61 x.x.x.. +..Esca < 0x00020: 70 65 20 63 68 61 72 61 63 74 65 72 20 69 73 20 pe char +acter is < 0x00030: xx xx xx xx xx xx xx xx '^^'... +. < 0x00000: 0d 0a 0d 0a 63 65 2d 6f 72 70 6b 66 6c 68 64 30 ....xx- +xxxxxxxxx < 0x00010: 30 77 2e 63 70 65 2e 66 6c 2e 6a 61 63 6b 73 76 xx.xxx. +xx.xxxxxx < 0x00020: 69 6c 20 4c 45 2d 33 31 31 76 20 30 30 3a 30 33 il xx-x +xxx xx:xx < 0x00030: 3a 31 38 3a 66 35 3a 39 39 3a 38 30 0d 0a 0d 0a :xx:xx: +xx:xx.... < 0x00040: 75 73 65 72 6e 61 6d 65 3a 20 usernam +e: xxxxxxxxxxx@xxxxxxxxxxx:~/xxxx/xxxxxxxxxxxxxxx/xxxxxxxxxx>
Input_log xxxxx:xxxxx#telnet x.x.x.x Trying x.x.x.x... Use configured source interface(xxxxx). Use x.x.x.x as local address. Connected to x.x.x.x. Escape character is '^^'. xxxxx xxxxx xxxxx username:

Here is the code I'm using for the telnet and the username/pw input. Again, the problem is that I cannot get Perl to output the username I am giving it.

$session_parent->cmd("telnet $cienaIP"); $session_parent->waitfor('/username: $/i'); $session_parent->print($username); # $session_parent->print('username'); I've tried this # $session_parent->cmd($username); I've tried this # $session_parent->login($username,$password); I've tried this # I've tried very long regex expressions thinking that maybe I need to + match # the whole expression "Trying x.x.x.x Use configured....username: " o +utput # but that hasn't helped either.

Replies are listed 'Best First'.
Re: Telnet to 1 router through another router
by jellisii2 (Hermit) on May 28, 2014 at 15:41 UTC
    You don't list what module you're using to help you with this, but I can recommend that you check out Control::CLI. I use it to hop between different machines through the proxy server and get work done.

      I used Net::Telnet. What is the difference between Control::CLI and Net::Telnet?

        Control::CLI uses Net::Telnet under the hood for telnet connections, so "probably not much, functionally". The code or the comment doesn't obviously indicate what you're using. :)
Re: Telnet to 1 router through another router
by andal (Hermit) on May 30, 2014 at 09:34 UTC

    Do you get any error? I've tried Net::Telnet to telnet second time and it worked for me without any problem. I don't understand why you set terminal length and width to 0. I didn't do anything of the kind.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-24 05:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found