in reply to Re: Passing telnet commands through SSH
in thread Passing telnet commands through SSH

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.

Replies are listed 'Best First'.
Re^3: Passing telnet commands through SSH
by Corion (Patriarch) on Jul 14, 2014 at 08:28 UTC

    As the error says, your login fails.

    If you are really, really sure that your username and password are correct, then most likely the prompt is not login name: but something else. Find that and correct that.

    Re^3: Passing telnet commands through SSH
    by wrongt (Initiate) on Jul 14, 2014 at 11:15 UTC
      I suppose telnet session filed because on the system where script is running have version of OpenSSH 4.3, but Net::OpenSSH module need OpenSSH 5.4 and upwards for creating tunnels. In case that i didn't have possibility to upgrade OpenSSH version is any alternatives way to create an ssh tunnel to gateway after that use tunnel to establish a telnet connection to remote host?
        Is netcat or socat or any other similar utility available on the remote side? you can use then to forward stdio to some remote TCP server.

        If Perl (or any other scripting language) is available on the remote side, you could also write your own netcat. See golf challenge: one-liner netcat clone