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

Hi, Apparently, we have some kind of heightened security on our cisco routers. Typically you could do the following:

Telnet Router
<enter password>
enable
<enter password>

However on our routers you have to do the following. Don't ask me why, it seems really stupid to me.

Telnet Router
<enter password>
login
<enter username>
<enter pasword>
enable
Anyhow, this is causing me serious problems when trying to use the NET::TELNET::CISCO perl module. Here is a snippet of what I am doing currently:
sub tftp_to_router { #connect a telnet session to the router my $cisco_session=Net::Telnet::Cisco->new(Host=>$router); #Login $cisco_session->login($username,$password); #Enable $cisco_session->enable($password); #ok we are in. Let's do our copy #tftp the file over #NONE OF THESE COMMANDS WORK BECAUSE AT THIS POINT, I AM #CONNECTED TO THE ROUTER, BUT NOT IN ENABLE MODE $cisco_session->cmd('copy tftp slot0'); $cisco_session->cmd('xxx.xxx.xxx.xxx'); $cisco_session->cmd('Source filename'); $cisco_session->cmd('Destination filename'); #Go to the directory on the router containing the startup-config file $cisco_session->cmd('cd slot0:'); #Erase it $cisco_session->cmd('erase startup-config'); #Copy the file we just tftp'd over to the startup-config $cisco_session->cmd('copy source startup-config'); #Copy that file to the slaveslot0: too $cisco_session->cmd('copy source slaveslot0:');
I tried adding the following before all the commands and it still did not work. $cisco_session->cmd('login\nusername\npassword'); Any help would be appreciated.

Thanks,

Brian Whyte

Replies are listed 'Best First'.
Re: Net::Telnet::Cisco Login Problem
by bobn (Chaplain) on Sep 12, 2003 at 13:34 UTC

    Net::Telnet Cisco is a subclass of Net::Telnet which has methods for turning on logging of data to/from the router, which would give you some ideal of what is going on, instead of saying "something broke".

    My recollcection is that Net::Telnet::Cisco can deal with receiving a password prompt instead of a username prompt upon connection. You may need to override the login method to deal with needing to send a login command before getting username and password prompts.

    Update: Actually you'll want to leave the login method alone, coying the parts you need out of it into a new method, I think.

    --Bob Niederman, http://bob-n.com

    All code given here is UNTESTED unless otherwise stated.

Re: Net::Telnet::Cisco Login Problem
by skaba9 (Beadle) on Sep 12, 2003 at 14:43 UTC
    This is a sloppy way of doing it, but it will work. I used this for Net::Telnet, but it should work for Net::Telnet::Cisco if it doesn't give Net::Telnet a try.

    $session->waitfor('/password:/'); #change to what the cisco prompts $session->print("password"); $session->waitfor('/router>/'); #change to "hostname"> $session->print("login"); $session->waitfor('/username:/'); $session->print("user"); #change to username $session->waitfor('/password:/'); $session->print("pass"); #change to password $session->waitfor('/router#/'); #change to "hostname"> or # $session->print("enablepass"); #change to enable password $session->waitfor('/router#/'); #change to "hostname"# #you shouldn't have to enable if your user has high enough privilege.
    Good luck
    sk
      I tested this out and it can be done a lot easier.

      $ok = $obj->print($firstpass); $ok = $obj->login($username, $password); $ok = $obj->enable($enablepass);
      I should have tested it first before posting.

      sk

      -- update - corrected typo