Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Net::Telnet::Cisco and Terminal Server

by perldragon80 (Sexton)
on Mar 16, 2006 at 23:39 UTC ( [id://537331]=perlquestion: print w/replies, xml ) Need Help??

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

I want to write a script that allows me to login to a terminal server, that is connected to a cisco router serial port:

But I am having a problem with the Net::Telnet::Cisco portion timing out. I assume this has to do with the console server interraction. Here are the exact steps I want to happen:
1)Telnet <IP> <Port number> of console server
2)Issue a couple carriage returns to bring up password prompt
3)Issue login password and then enable password
4)Once logged in, issue some commands
5)Logout

Any help is greatly appreciated! (Code Snippet Below)
my $session = Net::Telnet::Cisco->new(Host => '192.168.200.20', port = +> '2036' ); # The following is not necessary because only a password # prompt is shown... $session->login('password','password'); my @output = $session->cmd("show version"); print @output; # Enable mode if ($session->enable("enable_password") ) { @output = $session->cmd('show interfaces eth summary'); print "My privileges: @output\n"; } else { warn "Can't enable: " . $session->errmsg; } $session->close;

Replies are listed 'Best First'.
Re: Net::Telnet::Cisco and Terminal Server
by zer (Deacon) on Mar 17, 2006 at 05:53 UTC
    ya ive had this exact problem. it was a hacked up job in the end but what worked for me was waiting for the prompt to come up by either sleeping or changing the timeout.

    CPAN NET::TELNET::CISCO

    Cisco inherits from telnet so

    use Net::Telnet::Cisco (); $t = new Net::Telnet::Cisco (Timeout => 10, Prompt => '/bash\$ $/');

    This is untested but should point you in the right direction
      Hi, Newbie to perl.I have similar issue.I'm trying to connect to a cisco device via terminal server. Manually, when the server is connected, the username prompt comes after a carriage return. How can I send this carriage return via my code. I tried different ways but nothing is working.The Username prompt doesn't come up and it gets timeout.Here's the snippet of my code.Whats wrong here ? Is there any better way of doing it ? use Net::Telnet::Cisco; # $host="10.10.10.30"; $port="2033"; $user="cisco"; $password="cisco"; my $session = Net::Telnet::Cisco->new( Host => $host, Port => $port, Prompt => '/.*#:/', Input_log => "input.log", Output_log => "output.log", Dump_Log => "dump.log", Timeout => 10); $session->always_waitfor_prompt; $session->waitfor_pause(0.6); #Sending new line for carriage return $session->print("\n"); #Checking whats the last promt $match = $session->last_prompt; print" Match: + $match"; #Wait for the username prompt and enter username @out = $session->waitfor('/Username:.*$/'); print "@out\n"; @out = $session->print($user); print "@out\n"; #Wait for the password prompt and enter the password #$session->waitfor_pause(0.6); # @out = $session->waitfor('/Password:.*$/'); print "@out\n"; @out = $session->print($password); print "@out\n"; #$session->always_waitfor_prompt; #Wait for enable password @out = $session->waitfor('/vcctest-30-6k\>/'); print "@out\n"; @out = $session->print("enable"); @out = $session->waitfor('/Password:.*$/'); print "@out\n"; @out = $session->print($password); @out = $session->close;

        Sorry, my previous post got messed up. Newbie to perl.I have similar issue.I'm trying to connect to a cisco device via terminal server. Manually, when the server is connected, the username prompt comes after a carriage return. How can I send this carriage return via my code. I tried different ways but nothing is working.The Username prompt doesn't come up and it gets timeout.Here's the snippet of my code.Whats wrong here ? Is there any better way of doing it ? Any help appreciated

        use Net::Telnet::Cisco; # $host="10.10.10.30"; $port="2033"; $user="cisco"; $password="cisco"; my $session = Net::Telnet::Cisco->new( Host => $host, Port => $port, Prompt => '/.*#:/', Input_log => "input.log", Output_log => "output.log", Dump_Log => "dump.log", Timeout => 10); $session->always_waitfor_prompt; $session->waitfor_pause(0.6); #Sending new line for carriage return $session->print("\n"); #Checking whats the last promt $match = $session->last_prompt; print" Match: + $match"; #Wait for the username prompt and enter username @out = $session->waitfor('/Username:.*$/'); print "@out\n"; @out = $session->print($user); print "@out\n"; #Wait for the password prompt and enter the password #$session->waitfor_pause(0.6); # @out = $session->waitfor('/Password:.*$/'); print "@out\n"; @out = $session->print($password); print "@out\n"; #$session->always_waitfor_prompt; #Wait for enable password @out = $session->waitfor('/vcctest-30-6k\>/'); print "@out\n"; @out = $session->print("enable"); @out = $session->waitfor('/Password:.*$/'); print "@out\n"; @out = $session->print($password); @out = $session->close;
Re: Net::Telnet::Cisco and Terminal Server
by leighsharpe (Monk) on Mar 17, 2006 at 03:09 UTC
    Obviously your login is failing.
    I've only used Net::Telnet a couple of times, and not on a Cisco, but I find that just issuing a carriage return and then sending the password ( via a $obj->cmd("\n$password")) works OK as a login.
Re: Net::Telnet::Cisco and Terminal Server
by zer (Deacon) on Mar 16, 2006 at 23:47 UTC
    ive had this problem before. Try placing a sleep between processes to wait for the server to respond and send the prompts. Can you post some code? maybe i can get a better idea of what is going on
      Ok, I updated it with a little basic code snippet, pretty much straight out of the Net::Telnet:Cisco docs. I will try to add a sleep, and see if that helps.
Re: Net::Telnet::Cisco and Terminal Server
by zer (Deacon) on Mar 17, 2006 at 00:13 UTC
    where does it usualy time out?
      It times out at the login attempt.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-07-24 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.