Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Cannot get enable> mode to work

by ArifS (Beadle)
on Sep 18, 2014 at 13:48 UTC ( [id://1101053]=perlquestion: print w/replies, xml ) Need Help??

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

I have a long script that is getting stuck while handling the > (enable) mode.
I am trying to authenticate in the following two senarios-

1)
username:
password:
Device>

1st scenario- getting stuck at Device>.

2)
Device>
Same for the 2nd scenario stuck at Device>.

use warnings; use Net::Telnet; my $Telnet = new Net::Telnet; my $InHandle = $Telnet->input_log("input.txt"); my $OutHandle = $Telnet->output_log("output.txt"); my $prmpt = '/[\w().-]*[\$#>:.]\s?(?:\(>\))?\s*$/'; $host="172.16.1.1"; $username = "user"; $password = "pass"; $enpwd = "enable"; my $telnet = Net::Telnet->new( Host => $host, Input_log => "input.log", Output_log => "output.log", Dump_Log => "dump.log", Timeout => 10); # provide host address $telnet->open("$host"); print "\n\n Connecting to $host\n"; # authentication @out = $telnet->waitfor('/Username: $/i') || next; $telnet->print($username); print "@out\n"; # for tshoot only @out = $telnet->waitfor('/Password: $/i') || next; $telnet->print($password); print "@out\n"; # for tshoot only # if enable, send "enable" and enable-pwd unless ($telnet->waitfor('/Username: $/i' | '/#/i')) { #$telnet->waitfor('/>/'); @out = $telnet->print('enable'); print "@out\n"; # for tshoot only @out = $telnet->print($enpwd); print "@out\n"; # for tshoot only } print "username, password, & enable mode authentication accepted-\n"; $telnet->close;
Output:
Connecting to 172.16.1.1 1 1 pattern match timed-out at c:\temp\dirB2D.tmp\testing 3.pl line 35 Press any key to continue . . . Connecting to 172.16.1.2 pattern match timed-out at c:\temp\dirEDA1.tmp\testing 3.pl line 26 Press any key to continue . . .
I get the username and password passes thru in Scenario 1 but gets stuck in enable. Scenario 2 with .1.2 it doesn't like @out = $telnet->waitfor('/Username: $/i').
Please help!

Updated: code

Replies are listed 'Best First'.
Re: Cannot get enable> mode to work
by Corion (Patriarch) on Sep 18, 2014 at 13:50 UTC

    Have you read the Net::Telnet debugging advice?

    In your code, you have

    if ($telnet->waitfor('/#/i')) { ...

    But in the example session, there is no # character. Is that maybe the problem?

Re: Cannot get enable> mode to work
by VinsWorldcom (Prior) on Sep 18, 2014 at 16:16 UTC

    I see "enable" - is this a Cisco device? Try Net::Telnet::Cisco which handles the Cisco-specific prompts and makes Telnet to Cisco devices easier than just using Net::Telnet by itself.

      I am trying to avoid net::telnet::cisco, as it doesn't give all the features, and had much more luck with the net::telnet.

      Anything wrong in the following format? -
      # authentication if ($telnet->waitfor('/Username: $/i')) { $telnet->print($username); } elsif ($telnet->waitfor('/Password: $/i')) { $telnet->print($password); } # Wait for the prompt, send "enable" and enable-pwd elsif ($telnet->waitfor('/>/')) { $telnet->print('enable'); $telnet->waitfor('/Password: $/i'); $telnet->print($enpwd); } else { $telnet->waitfor('/>/'); $telnet->print('enable'); $telnet->waitfor('/Password: $/i'); $telnet->print($enpwd); }
      It doesn't like the format. But individually works just fine.....

        Net::Telnet::Cisco subclasses Net::Telnet, so everything you have in Net::Telnet is actually available in Net::Telnet::Cisco.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2024-04-23 12:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found