Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

telnet to a device from server, over an existing ssh connection between client / server

Here is the issue. I was using my script to connect to a device directly over a telnet connection (from my windows desktop <=(telnet)=> to the device). Basicly, my script run some commands in TL1, capture the output and proceed according the parameter values... pretty straight forward.

This device will be install on another network, which i can't reach anymore by telnet directly. Now, i have to start an ssh connection on the specific server and then, start the telnet session from there. (from my windows desktop <=(ssh)=> server <=(telnet)=> to the device)

I understand the basic of paramiko... i found that code on jessenoler website:

import paramiko
ssh.connect('127.0.0.1', username='jesse', password='lol')
stdin, stdout, stderr = ssh.exec_command("uptime")
type(stdin)
stdout.readlines()
# output:
# ['13:35  up 11 days,  3:13, 4 users, load averages: 0.14 0.18 0.16\n']

I can't figure out how i could initiate a telnet from the server... Should i use :

ssh.exec_command("telnet 10.10.10.10 10001")

I know the easiest way to solve my problem is to have install python on the server, but i can't. Someone faced that kind a problem before? Thanks for the input! :)

like image 844
oliver Avatar asked Oct 21 '25 04:10

oliver


1 Answers

You should setup an SSH tunnel instead of opening a normal connection. This can be done from the command line on your client with -L localport:server:remoteport, or it can be done from python with paramiko.

Take a look at this answer and the linked gist for details of how to do it with Python.

When you've set this up, you should connect with telnet to localhost on the port specified as localport.

like image 127
Kleist Avatar answered Oct 23 '25 19:10

Kleist