Hi,
i'm using Net::OpenSSH to create a tunnel via SSH gateway after that i want to connect to other remote host via telnet, here is my code:
my $ssh = Net::OpenSSH->new('user@1.1.1.2');
my ($socket, $pid) = $ssh->open_tunnel('1.2.0.1', 23);
my $telnet = Net::Telnet->new(-fhopen => $socket,
-prompt => '/.*\$ $/',
-telnetmode => 0,
-cmd_remove_mode => 0,
-output_record_separator => "\r");
$telnet->waitfor(-match => '/login\ name\:/',
-errmode => "return")
or die "login failed: " . $telnet->lastline;
my @lines = $telnet->cmd("who");
print Dumper(@lines);
$telnet->close;
but code is always stop on this line:
or die "login failed: " . $telnet->lastline;
i get the following output:
login failed: at test.pl line 21.
Could you please help me to successfully achieve connection to telnet host.
Thank you.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.