bgi has asked for the wisdom of the Perl Monks concerning the following question:

Hi

Im trying the following:

I have a workling connection via SSH to a server and now i want to the next hop via Telnet...i want to do this with the module Net::Telnet...

My problem is: How can I put the functions of the Telnet module through the channel?

My code so far:

use strict; use Net::SSH2; use Net::Telnet; my $ssh1= Net::SSH2-> new(); if($ssh1-> connect('204.230.74.17', '22')){print "connect1 ok \n";} # +or die "conncet to SSH1 failed"; if($ssh1-> auth_password('ddd', 'pass')){print "auth1 ok \n";} # or di +e "auth1 failed"; if($ssh1-> tcpip('134.46.156.237:22', '127.0.0.1:22')){print "tunnel o +k \n";} my $ssh2= Net::SSH2-> new(); if($ssh2-> connect('127.0.0.1', '22')){print "connect2 ok \n";}# or di +e "conncet to SSH2 failed"; if($ssh2-> auth_password('ddd','pass')){print "auth2 ok \n";}# or die +"auth2 failed"; my $chan1= $ssh2-> channel(); my $telnet = Net::Telnet-> new (); if($telnet-> open(Host=> '127.0.0.1', Port=> '22')){print "telnet ok"; +}#; $telnet-> login(Name=> 'ddd', Password=> 'pass'); $a= $telnet-> get();


regards from germany

Replies are listed 'Best First'.
Re: Net::SSH2 and Net::Telnet
by casiano (Pilgrim) on Jun 03, 2008 at 09:12 UTC
    Is untested code so I am not really sure about it:
    use strict; use GRID::Machine; my $host = shift || 'ddd@204.230.74.17'; my $machine = GRID::Machine->new(host => $host, uses => [ 'Net::Telnet +' ]); my $r = $machine->eval(q{ my $telnet = Net::Telnet-> new(); gprint "telnet ok" if $telnet-> open(Host=> '127.0.0.1', Port=> '22') +; $telnet-> login(Name=> 'ddd', Password=> 'pass'); my $a= $telnet-> get(); $a; }); print $r->result; # prints the contents of $a above
    I am using GRID::Machine instead of Net::SSH2. You have to set automatic autentification before using GRID::Machine.

    Hope it helps

    Casiano

Re: Net::SSH2 and Net::Telnet
by bgi (Sexton) on Jun 18, 2008 at 10:59 UTC
    Are there any issues with GRID::Machine on Windows?

    Regards