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

Re: How do I connect to cisco pix via ssh?

by Anonymous Monk
on Jun 07, 2004 at 08:22 UTC ( [id://361906]=note: print w/replies, xml ) Need Help??


in reply to How do I connect to cisco pix via ssh?

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-24 20:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found