4

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! :)

oliver
  • 43
  • 1
  • 3
  • that would establish a telnet connection to the device, true. But it would be only between the device and the server, not trivially accessible from within your script. I'd create a SSH Tunnel between the desktop and the server (using ssh -L), and telnet through it from the desktop to the device directly, using the telnetlib module. – ch3ka Apr 20 '12 at 17:18
  • Hi ch3ka, thanks for the input! Never done that before. I guess i have to do the forward on the server side. or i could initiate the ssl -L only on my desktop? i'm a bit confuse. i'll keep reading about forwarding. – oliver Apr 20 '12 at 20:16

1 Answers1

3

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.

Community
  • 1
  • 1
Kleist
  • 7,785
  • 1
  • 26
  • 30