简体   繁体   中英

telnet through SSH

I need to connect a remote computer via ssh and then make a telnet connection to its port

(telnet localhost #port)

with JAVA

I tried some libraries (sshd, ganymed) and succesfully login to remote computer but cannot login to telnet. The problem is that the libraries open a ssh connection and run "one" command at a time. However telnet login is interactive. It asks for username then i'm writing it to stream (with EOF) but hangs there forever

I cannot find a proper way for implementation. Any advice?

(using linux)

You could try to tunnel telnet over SSH, then you could open the telnet session on the original host running the java program. Not sure if/how you could do that in Java though.

In putty you can configure the tunnel in connection/ssh/tunnels, there you can enter a remote port (for example 23) and a local unused port (lets say 2323). Then you can open a telnet connection on the original host to 2323 which gets forwarded to the remote host port 23 via ssh.

Can't you just call Runtime.exec("ssh telnet "), which should drop you straight into the telnet session you need. Try it on the shell. Runtime.exec() returns a Process object which you can use to read from and write to the resulting Process object.

Also, if you are indeed sending EOF after the username that likely is the cause of your issues. You should send CR or CR/LF after the username.

I made a Ganymede SSH-2 plugin for the JTA - Java Terminal Adapter. Very simple. You could run it up yourself, or if you contact me off list I can provide it to you. It's been running in production for a year or so, very stable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM