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

Dear Monks, I wrote simple script that takes telnet connection and convert it to serial the port, i.e. When I write "telnet 127.0.0.1 9000" it takes me to the prompt of the serial device.

I use:

$server = IO::Socket::INET->new(Proto=>'tcp', LocalPort=> 9000, Listen=> SOMAXCONN, Reuse =>1) or die "Can't bind: $!\n";
It's working fine,

Now, I would like to do the same with SSH connection. Anyone have an idea how to config the IO::Socket::INET for use "ssh -p 9000 127.0.0.1" ? Thanks In advance, Mosh.

Janitored by Arunbear - added code tags, as per Monastery guidelines

Replies are listed 'Best First'.
Re: ssh with IO::Socket::INET
by edan (Curate) on Nov 01, 2004 at 10:19 UTC
      Thanks but, I meant SSH connection and not SSL ... mosh.
Re: ssh with IO::Socket::INET
by mosh (Scribe) on Nov 01, 2004 at 12:23 UTC
    Explanations:
    I have a server SW that runs on Linux and listens to port 9000.
    The server's aim is to direct TCP session that opens on port 9000 to rs-232 (serial port).
    So one could open telnet to the server's IP port 9000 , and he will get the prompt of the serial device (the prompt that you get while connecting through Hyper Terminal).

    Now, I would like to use the server, but, instead of opening telnet - opening ssh.
    i.e. instead of directing telnet to serial, I would like to direct ssh to serial.
    In another words, instead of writing on my Linux "telnet 127.0.0.1 9000", I would like to do "ssh -p 9000 127.0.0.1" or something like that.

    I hope it is more clear.

    Mosh.

      You want to do some port forwarding by the sound of it. See the appserver example here Another option is stunnel

      cheers

      tachyon

      If you want the server written in Perl, you will need to write it. Net::SSH::Perl is client only. AFAIK, there is no SSH server implementation in Perl.

      There are other solutions. One is to use SSH port forwarding. Your server listens for telnet or plain socket connections on localhost. SSH is used for the authentication and encryption. This forwards port 9000 on the localhost to 127.0.0.1 port 9000 on the remote host. I have used similar commands to foward rdesktop and VNC connections.

      ssh -f -N -L 9000:127.0.0.1:9000

      An alternative is to make your server into a program that runs on the command line. Then from a normal ssh shell prompt, run your command. You can even have the account automatically run your command.

      BTW, if you are really are on 127.0.0.1, there isn't much point in using SSH. The connection isn't going over the network so security isn't a problem.