Perl SSH连接执行telnet

我尝试通过中央管理服务器访问路由器作为“ssh hop”服务器
#!/usr/bin/perl -X

use strict;
use Net::OpenSSH;
use Net::Telnet;

my $lhost = "linuxserver";
my $luser = "linuxuser";
my $lpass = "linuxpassword";

my $chost = "routername";
my $cpass = "Routerpassword";

my $prompt = '/(?:Password: |[>])/m';
my @commands = ("show usersr");

my $ssh = Net::OpenSSH->new($lhost,
'user' => $luser,
'password' => $lpass,
'master_opts' => [ '-t' ],
#'async' => 1 # if enabled then password cannot be set here
);
my ($pty, $err, $pid) = $ssh->open2pty("telnet $chost");

my $t = new Net::Telnet(
-telnetmode => 0,
-fhopen => $pty,
-prompt => $prompt,
-cmd_remove_mode => 1,
-output_record_separator => "r",
#-dump_log => "debug.log",
);

my $end = 0;

while (!$end) {
  my ($pre, $post) = $t->waitfor($prompt);
  if ($post =~ /Password: /m) {
    # send password
    $t->print("$cpass");
  }
  elsif ($post =~ /[>#]/ && @commands) {
    my $cmd = shift(@commands);
    if ($cmd !~ /[rn]/) {
      $t->print($cmd);
    }
    else {
      print $t->cmd($cmd);
    }
  }
  else {
    $end = 1;
    $t->cmd("exit");
  }
}
#close $pty;
$t->close();
不幸的是我总是收到以下错误: 读错误:test.pl第71行的输入/输出错误 有人可以帮助我,还是有更好的解决方案,只测试是否可以通过“跳”服务器进行telnet连接? 连接看起来像: 工作站--ssh-> server --telnet-> router 提前致谢。     
已邀请:
我认为最好的选择是建立到管理服务器的SSH隧道,并使用它来远程登录到路由器。     
让Net :: Telnet在Net :: OpenSSH上运行有时并不像它应该的那样容易,它需要一些实验来获得正确的标志和调用组合,使其工作。 例如,不使用telnet到目标主机,而是使用netcat打开原始连接(如果代理上允许隧道,则使用Net :: OpenSSH支持TCP转发)。 期待+ Net :: OpenSSH可能是更好的选择。     

要回复问题请先登录注册