Perl SSH connection to execute telnet -


i tried following access router via central admin server "ssh hop" server

 #!/usr/bin/perl -x  use strict; use net::openssh; use net::telnet;  $lhost = "linuxserver"; $luser = "linuxuser"; $lpass = "linuxpassword";  $chost = "routername"; $cpass = "routerpassword";  $prompt = '/(?:password: |[>])/m'; @commands = ("show users\r");  $ssh = net::openssh->new($lhost, 'user' => $luser, 'password' => $lpass, 'master_opts' => [ '-t' ], #'async' => 1 # if enabled password cannot set here ); ($pty, $err, $pid) = $ssh->open2pty("telnet $chost");  $t = new net::telnet( -telnetmode => 0, -fhopen => $pty, -prompt => $prompt, -cmd_remove_mode => 1, -output_record_separator => "\r", #-dump_log => "debug.log", );  $end = 0;  while (!$end) {   ($pre, $post) = $t->waitfor($prompt);   if ($post =~ /password: /m) {     # send password     $t->print("$cpass");   }   elsif ($post =~ /[>#]/ && @commands) {     $cmd = shift(@commands);     if ($cmd !~ /[\r\n]/) {       $t->print($cmd);     }     else {       print $t->cmd($cmd);     }   }   else {     $end = 1;     $t->cmd("exit");   } } #close $pty; $t->close(); 

unfortunately following error: read error: input/output error @ test.pl line 71

can me please or there better solution test if telnet connection via "hop" server possible or not?

the connection looks like: workstation --ssh-> server --telnet-> router

thanks in advance.

i think best option make ssh-tunnel admin server , use telnetting router.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -