• Publicidad

Problema con conexión a Router Cisco vía SSH

¿Eres administrador de sistemas? Este foro es para todos aquellos temas relacionados con el uso de Perl para administración de sistemas.

Problema con conexión a Router Cisco vía SSH

Notapor spacepecjks » 2012-09-25 13:10 @590

¡Que tal a todos!

Estoy intentando conectarme a un enrutador Cisco vía SSH con Perl, el problema que tengo es que como que no logro que se ejecute cualquier comando, siento que no se logra a conectar, la verdad quisiera ver si alguno puede ayudarme con este detalle que tengo; aquí les dejo mi código y el resultado que me arroja:

código:
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!c:\perl\bin\perl.exe
  2. print "content-type: text/html \n\n";
  3. $ENV{HOME} = $ENV{USERPROFILE};
  4. use strict;
  5. use warnings;
  6. use Net::SSH::Perl;
  7. my $host = '10.2.90.1';
  8. my $pass = 'cisco';
  9. my $user = 'cisco';
  10. my $cmd  = 'show who';
  11. my $ssh = Net::SSH::Perl->new($host, protocol => '2,1', debug => 1,interactive=>0);
  12. $ssh->login($user,$pass);
  13. print "\n\n\n";
  14.    my @interface = $ssh->cmd($cmd);
  15.         print "la interface es:  @interface\n\n\n";
  16. exit;
Coloreado en 0.003 segundos, usando GeSHi 1.0.8.4


resultado:
Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
VDDG00U05EXCOMX: Reading configuration data C:\Users\VDDG00U/.ssh/config
VDDG00U05EXCOMX: Reading configuration data /etc/ssh_config
VDDG00U05EXCOMX: Connecting to 10.213.19.1, port 22.
VDDG00U05EXCOMX: Remote protocol version 2.0, remote software version Cisco-1.25

VDDG00U05EXCOMX: Net::SSH::Perl Version 1.34, protocol version 2.0.
VDDG00U05EXCOMX: No compat match: Cisco-1.25.
VDDG00U05EXCOMX: Connection established.
VDDG00U05EXCOMX: Sent key-exchange init (KEXINIT), wait response.
VDDG00U05EXCOMX: Algorithms, c->s: 3des-cbc hmac-sha1 none
VDDG00U05EXCOMX: Algorithms, s->c: 3des-cbc hmac-sha1 none
VDDG00U05EXCOMX: Entering Diffie-Hellman Group 1 key exchange.
VDDG00U05EXCOMX: Sent DH public key, waiting for reply.
VDDG00U05EXCOMX: Received host key, type 'ssh-rsa'.
VDDG00U05EXCOMX: Host '10.213.19.1' is known and matches the host key.
VDDG00U05EXCOMX: Computing shared secret key.
VDDG00U05EXCOMX: Verifying server signature.
VDDG00U05EXCOMX: Waiting for NEWKEYS message.
VDDG00U05EXCOMX: Send NEWKEYS.
VDDG00U05EXCOMX: Enabling encryption/MAC/compression.
VDDG00U05EXCOMX: Sending request for user-authentication service.
VDDG00U05EXCOMX: Service accepted: ssh-userauth.
VDDG00U05EXCOMX: Trying empty user-authentication request.
VDDG00U05EXCOMX: Authentication methods that can continue: password.
VDDG00U05EXCOMX: Next method to try is password.
VDDG00U05EXCOMX: Trying password authentication.
VDDG00U05EXCOMX: Login completed, opening dummy shell channel.
VDDG00U05EXCOMX: channel 0: new [client-session]
VDDG00U05EXCOMX: Requesting channel_open for channel 0.
VDDG00U05EXCOMX: channel 0: open confirm rwindow 8192 rmax 4096
VDDG00U05EXCOMX: Got channel open confirmation, requesting shell.
VDDG00U05EXCOMX: Requesting service shell on channel 0.



VDDG00U05EXCOMX: channel 1: new [client-session]
VDDG00U05EXCOMX: Requesting channel_open for channel 1.
VDDG00U05EXCOMX: Entering interactive session.
VDDG00U05EXCOMX: Channel open failure: 1: reason 4:
Use of uninitialized value in join or string at c:\xampp\cgi-bin\ssh_test5.pl li
ne 30.
Use of uninitialized value in join or string at c:\xampp\cgi-bin\ssh_test5.pl li
ne 30.
Use of uninitialized value in join or string at c:\xampp\cgi-bin\ssh_test5.pl li
ne 30.
la interface es:
 
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4

En verdad espero puedan ayudarme, de antemano les agradezco ;)
Última edición por spacepecjks el 2012-09-25 13:42 @612, editado 1 vez en total
Avatar de Usuario
spacepecjks
Perlero nuevo
Perlero nuevo
 
Mensajes: 9
Registrado: 2010-01-29 12:50 @576

Publicidad

Re: Problema con conexión a Router Cisco vía SSH

Notapor explorer » 2012-09-25 13:37 @609

El mensaje de error dice que falta por instalar el módulo Crypt::RSA.
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14476
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Problema con conexión a Router Cisco vía SSH

Notapor spacepecjks » 2012-09-25 13:43 @613

¡Gracias por responder, explorer!

¿Sabes? Instalé el módulo y ahora me tira el siguiente error. ¿Tú qué crees que esté ocurriendo?
Avatar de Usuario
spacepecjks
Perlero nuevo
Perlero nuevo
 
Mensajes: 9
Registrado: 2010-01-29 12:50 @576

Re: Problema con conexión a Router Cisco vía SSH

Notapor explorer » 2012-09-25 14:07 @630

Notas:
* es 'explorer', no 'Explorer' :)
* acostúmbrate, por favor, a respetar y poner las marcas que rodean las zonas de texto, Perl, etc.

Así, quedará mejor el mensaje.

El mensaje de error dice que en la línea 30 del programa se está usando una variable no inicializada dentro de una concatenación o interpolación.

Si esa línea 30 corresponde a la 15 del código que publicaste, entonces quiere decir que la variable @interface está indefinida, lo que, según la documentación del módulo, quiere decir que los tres valores devueltos por cmd() están indefinidos, por lo que la ejecución de 'show who' no ha devuelto nada a la salida estándar, a la salida estándar de errores, y el valor resultado de la ejecución.
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14476
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Problema con conexión a Router Cisco vía SSH

Notapor spacepecjks » 2012-09-26 09:55 @454

¡Qué tal otra vez!

Espero puedan seguir ayudándome, y es que la conexión que pretendo tener al enrutador Cisco, aún no lo logro. Si pueden observar, en una de las líneas finales me marca: {Channel open failure: 1: reason 4:} y en efecto no recibo nada en las variables de salida, y siento que eso es debido a que el comando “show who” no se ejecuta. ¿Ustedes saben cómo podría solucionarlo?
NOTA: Aquí les dejo el resultado que me arroja:

[syntax lines=geshi-n]VDDG00U05EXCOMX: Reading configuration data C:\Users\VDDG00U/.ssh/config
VDDG00U05EXCOMX: Reading configuration data /etc/ssh_config
VDDG00U05EXCOMX: Connecting to 10.213.19.1, port 22.
VDDG00U05EXCOMX: Remote protocol version 2.0, remote software version Cisco-1.25

VDDG00U05EXCOMX: Net::SSH::Perl Version 1.34, protocol version 2.0.
VDDG00U05EXCOMX: No compat match: Cisco-1.25.
VDDG00U05EXCOMX: Connection established.
VDDG00U05EXCOMX: Sent key-exchange init (KEXINIT), wait response.
VDDG00U05EXCOMX: Algorithms, c->s: 3des-cbc hmac-sha1 none
VDDG00U05EXCOMX: Algorithms, s->c: 3des-cbc hmac-sha1 none
VDDG00U05EXCOMX: Entering Diffie-Hellman Group 1 key exchange.
VDDG00U05EXCOMX: Sent DH public key, waiting for reply.
VDDG00U05EXCOMX: Received host key, type 'ssh-rsa'.
VDDG00U05EXCOMX: Host '10.213.19.1' is known and matches the host key.
VDDG00U05EXCOMX: Computing shared secret key.
VDDG00U05EXCOMX: Verifying server signature.
VDDG00U05EXCOMX: Waiting for NEWKEYS message.
VDDG00U05EXCOMX: Send NEWKEYS.
VDDG00U05EXCOMX: Enabling encryption/MAC/compression.
VDDG00U05EXCOMX: Sending request for user-authentication service.
VDDG00U05EXCOMX: Service accepted: ssh-userauth.
VDDG00U05EXCOMX: Trying empty user-authentication request.
VDDG00U05EXCOMX: Authentication methods that can continue: password.
VDDG00U05EXCOMX: Next method to try is password.
VDDG00U05EXCOMX: Trying password authentication.
VDDG00U05EXCOMX: Login completed, opening dummy shell channel.
VDDG00U05EXCOMX: channel 0: new [client-session]
VDDG00U05EXCOMX: Requesting channel_open for channel 0.
VDDG00U05EXCOMX: channel 0: open confirm rwindow 8192 rmax 4096
VDDG00U05EXCOMX: Got channel open confirmation, requesting shell.
VDDG00U05EXCOMX: Requesting service shell on channel 0.
VDDG00U05EXCOMX: channel 1: new [client-session]
VDDG00U05EXCOMX: Requesting channel_open for channel 1.
VDDG00U05EXCOMX: Entering interactive session.
VDDG00U05EXCOMX: Channel open failure: 1: reason 4:
Use of uninitialized value in concatenation (.) or string at c:\xampp\cgi-bin\ss
h_test5.pl line 35.

De antemano les agradezco.
Avatar de Usuario
spacepecjks
Perlero nuevo
Perlero nuevo
 
Mensajes: 9
Registrado: 2010-01-29 12:50 @576

Re: Problema con conexión a Router Cisco vía SSH

Notapor explorer » 2012-09-26 13:34 @607

Google me dice que es un problema del SSH utilizado en la máquina Cisco.

Te recomiendo usar Net::SSH2.

Según parece, hay una limitación en el número de canales SSH que permite abrir en una misma conexión.

Según lo que pone en el manual de Net::SSH::Perl:
$ssh->login([ $user [, $password [, $suppress_shell ] ] ])

Por defecto, Net::SSH::Perl abrirá un canal con un shell dentro de él. Esto es lo que normalmente usted quiere que pase. Si está tunelizando otro protocolo sobre SSH, sin emabargo, quizás quiera impedir este comportamiento. Pasando un valor verdadero a $suppress_shell impedirá que un canal shell sea abierto (solo en SSH2).

Prueba a ver si esta solución te vale.

Otro intento es poner la opción "use_pty => 0".
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14476
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Problema con conexión a Router Cisco vía SSH

Notapor spacepecjks » 2012-10-03 12:02 @543

¡Qué tal a todos otra vez!

Les comento que he seguido tratando de conectarme a la caja de Cisco vía SSH y lo he logrado, gracias por sus recomendaciones en especial al Administrador ya que logré conectarme con el módulo que me sugirió (NET::SSH2), por ende, aquí les comparto el código para que lo revisen y propongan las mejoras.

Saludos y muchas gracias! - ;)

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. print "content-type: text/html \n\n";
  2. use Net::SSH2;
  3. my $ssh2 = Net::SSH2->new();
  4. $ssh2->connect("xxx.xxx.xxx.xxx") or die "No se puede establecer conexión con el host $@ \n";
  5. $ssh2->auth_password('usuario','password');
  6. my $chan = $ssh2->channel();
  7. $chan->exec('show version');
  8. my $buflen = 10000;
  9. my $buf1 = "0" x $buflen;
  10. $chan->read($buf1, $buflen);
  11. print "BUF1:\n", $buf1,"\n";
  12. $chan->exec("exit");
  13. $ssh2->disconnect();
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4
Avatar de Usuario
spacepecjks
Perlero nuevo
Perlero nuevo
 
Mensajes: 9
Registrado: 2010-01-29 12:50 @576


Volver a Administración

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 2 invitados

cron