Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: Changing a script from Net::Telnet to Net::SSH2

by dasgar (Priest)
on Mar 03, 2016 at 21:38 UTC ( [id://1156770]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Changing a script from Net::Telnet to Net::SSH2
in thread Changing a script from Net::Telnet to Net::SSH2

I completely misunderstood what you were trying to do. Based on your problem description, I thought you were connecting to something via telnet and now wanted to connect via SSH. But what you're now describing is needing to SSH into one system and then from there telnet into a second system. That's a completely different scenario.

Now that I understand what it is you're trying to do, I agree with perlfan that creating an SSH tunnel is probably what you might want to consider. After you create the tunnel, your existing code using Net::Telnet just needs to connect to the local port of the SSH tunnel.

Replies are listed 'Best First'.
Re^4: Changing a script from Net::Telnet to Net::SSH2
by jtzako (Sexton) on Mar 03, 2016 at 22:18 UTC
    Ok. That sounds reasonable. I just have to figure out how to make the SSH2 tunnel. Also not sure what you meant by connecting the the local port. I'm not really a programmer by trade so having to do a lot of research.

      The basic idea of an SSH tunnel is that the SSH client connects to an SSH server and it will map a local port to a remote port. That means that anything that connects to the local port will get forwarded to a remote system and port. For example, you have an SSH server at 192.168.1.1 and a telnet server at 192.168.2.1. You can use an SSH client to connect to the SSH server and configure a tunnel that will map local port 23 (i.e. 127.0.0.1:23) to port 23 on the telnet server (i.e. 192.168.2.1:23). Then you can use a telnet client and tell it to connect to local port 23 (127.0.0.1:23) and the SSH client will route that to 192.168.2.1:23 via the SSH server.

      You can go to this Wikipedia page (click here) to get some more information. Unfortunately, the example near the end of the page is not the type of port that you would need to setup. Click here for an example of how to do this from a Linux environment. From a Windows system, you can use putty as an SSH client. See here for instructions on how to setup a tunnel using the GUI interface for putty or you can look here for information on how to setup a tunnel via command line parameters.

      In your case, you can manually use an SSH client to establish a connection to your SSH server and to create the needed tunnel. Going that route means that you probably don't need to change your code - if I understand your situation correctly. Alternatively, you can use Net::SSH2 (or other appropriate SSH related modules) to connect to the SSH server and create the tunnel within your code.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-03-28 10:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found