1

How to telnet network device via jump server(SSH) using paramiko or any other library

I am able to SSH jumpserver and able to SSH other device over it. But need solution to telnet from jumpserver.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
murali
  • 11
  • 1

1 Answers1

0

Use SSH port forwarding.

Modifying the code from Nested SSH using Python Paramiko for telnet, you get a code like this:

# establish SSH tunnel
self.ssh = paramiko.SSHClient()
# ...
self.ssh.connect(hostname=ssh_host, username=ssh_user, password=ssh_password)

transport = ssh_client.get_transport()
dest_addr = (telnet_host, telnet_port)
local_unique_port = 4000 # any unused local port
local_host = 'localhost'
local_addr = (local_host, local_unique_port)
vmchannel = vmtransport.open_channel("direct-tcpip", dest_addr, local_addr)

tn = telnetlib.Telnet(local_host, local_unique_port)
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992