Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

i've had problems getting perl to ssh to a Cisco.

it seems that Cisco's sshd is incompatible with Net::SSH::Perl. run both the module and the system ssh in verbose mode and you'll see that N:S:P opens two channels, one for a global-like session or some such, then another for each cmd that is sent. plain ssh only uses only one channel for a shell (or a command). i got far enough down in debugging to see that the first channel autenticates fine, but it seems the Cisco's sshd doesn't support more than a single channel, the second channel created for the cmd fails with some sort of 'out of resource' message.

my current solution is to use Expect and the system ssh command (which works fine).

i'll create a trouble ticket with Cisco for this issue once i pin it down and have some time to try again and take notes. (and make sure i'm not missing something)

this may or may not help...

package NE; use base 'Expect'; # from Net::Telnet::Cisco $prompt = qr/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enab +le\))?\s*$)/; sub cmd { my ( $exp, $cmd ) = @_; $exp->print($cmd, "\n"); $exp->expect( 10, -re => $prompt ) or return; $out = $exp->before; $match = $exp->match; $out =~ s/^$cmd\r?\n//; return $out; } sub login { my ( $exp, $user, $pass ) = @_; $exp->expect( 10, [ qr/[Pp]assword:\s*/, sub { my $exp = shift; $exp->print($pass, "\n"); exp_continue; }], [ qr/[Uu]sername:\s*/, sub { my $exp = shift; $exp->print($user, "\n"); exp_continue; }], -re => $prompt, ); } sub enable { my ( $exp, $pass ) = @_; $exp->print("enable", "\n"); $exp->login( '', $pass ); } package main; #$Expect::Debug = 1; $Expect::Log_Stdout = 0; my $exp = NE->new(); $exp->spawn(qw| /usr/bin/ssh -2 -l admin myrouter |) or die "spawn: $!\n"; $exp->login( '', "******" ); $exp->enable( "**********" ); my ( $out ); $exp->cmd( "terminal length 0" ); ( $out ) = $exp->cmd( "show running-config" ); print $out; $exp->cmd( "exit" ); $exp->soft_close(); exit;

another possibility yet to be investigated is using Net::SSH::Perl for the connection, trying to fish out the filhandle that it creates and pass it to Net::Telnet::Cisco directly and use Net::Telnet::Cisco for the cmd handling. this will probably take some hacking as it looks like the first Net::SSH::Perl channel is opened with different parameters than the channels opened for the commands.

another possibility might be the Web interface. i haven't played with that at all yet.


In reply to Re: How do I connect to cisco pix via ssh? by Anonymous Monk
in thread How do I connect to cisco pix via ssh? by Nalina

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-03-29 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found