을 실행하기 위해 "ssh를 홉"서버와 중앙 관리 서버를 통해 라우터에 액세스하려면 다음펄 SSH 연결은 내가 노력 텔넷
#!/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 users\r");
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 !~ /[\r\n]/) {
$t->print($cmd);
}
else {
print $t->cmd($cmd);
}
}
else {
$end = 1;
$t->cmd("exit");
}
}
#close $pty;
$t->close();
불행하게도 나는 항상 다음과 같은 오류 얻을 : 읽기 오류 : 입력/출력 test.pl 라인에서 오류가 발생했습니다. 012
누군가 제게 도와 주실 수 있습니까? 아니면 "홉"서버를 통한 텔넷 연결이 가능한지 테스트 할 수있는 더 나은 해결책이 있습니까? 사전에 워크 스테이션 --ssh-> 서버 --telnet-> 라우터
감사 :
연결이 같은 보인다.
원격 SSH 호스트에'telnet'를 실행하고 새로운'순 :: Telnet' 세션에 ssh를 청각 장애를 연결하려는 것 같습니다. 그게 효과가 없을거야. 어쩌면 Expect를 들여다 볼까? http://search.cpan.org/~rgiersig/Expect-1.21/Expect.pod – friedo
라우터에 텔넷 세션이 관리 서버에서 가능하다면 난 단지 확인하시기 바랍니다. 텔넷을 통해 ssh와 라우터를 통해서만 관리 서버에 연결할 수 있습니다. 그래서 또 다른 가능성이 있다면 나는 그것을 사용할 것입니다. 하지만 난 정말 펄에 익숙하지 않아 좀 더 도움이 필요해 .-) – Stefan