Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Telnet over SSH2 from Windows

by salva (Canon)
on Mar 27, 2010 at 21:59 UTC ( [id://831410]=note: print w/replies, xml ) Need Help??


in reply to Telnet over SSH2 from Windows

If tunnels are not forbidden in the intermediate host, you could use some SSH client (OpenSSH or plink from PuTTY) to create a tunnel from your local machine to the target device telnet port. Then, use Net::Telnet to talk to the remote machine through the tunnel.

If tunnels are not enabled, you could run netcat or socat in the intermediate machine to obtain a similar effect. I believe that later versions of Perl for Windows already have an emulation of socketpair, so you would be able to do something like...

Net::Telnet ===> socketpair ===> plink ===> netcat ===> destination h +ost/port \_______________ ____________/ \___ ___/ \/ \/ Local machine Intermediate machine

Replies are listed 'Best First'.
Re^2: Telnet over SSH2 from Windows
by Hessu (Hermit) on Mar 28, 2010 at 18:05 UTC
    Hello,

    Plink was nice suggestion because it worked. With command string below, I was able first to establish tunnel via SSH server to the device with telnet and command it with Net::Telnet. The plink command explanation can be found from plink documentation and it is also quite nicely explained in HOWTO ssh port-forwarding.

    I am still more than happy to hear explanations why reading during telnet session seems to break the write and if this is somehow doable from Windows.

    Thank You
    # From DOS prompt, give command below and leave the session open. # Version 0.60 from plink is needed because it contains the -nc # parameter. Version 0.58 did not have this parameter. The remote # host in here is the device IP address being access via telnet. # # plink.exe -L 1555:(remote host):(remote port) (ssh server) -l <user +name> -pw <password> -nc (remote host):(remote port) #!/usr/bin/perl -w use strict; use warnings; use Net::Telnet; use Data::Dumper; my $telnet = (); my @l_resp_a = (); $telnet = Net::Telnet->new( Timeout => 10, Host => 'localhost', # or 127.0.0.1 Port => 1555 ); if( $telnet ){ print "connected\n"; $telnet->prompt('/<expected prompt>/'); $telnet->cmd( String => 'ls -al', Output => \@l_resp_a ); } else{ print "failed to connect"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://831410]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 03:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found