I want to write code to execute some commands through telnet connection so i can get data from server. But i should be connected to server via ssh first, then connect via telnet. I'm already trying implement python script using paramiko & telnet lib. But i don't know why my telnet connection always failed with operation timed out exception.
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip, username=usr, password=pswd)
rc = ssh.invoke_shell()
output = rc.recv(65535)
print output
tn = telnetlib.Telnet(iptelnet)
tn.read_until("Username:")
tn.write(usr + "\n")
tn.read_until("Password:")
tn.write(pswd + "\n")
tn.write("some command")
result = tn.read_all()
print result
I'm new in python so i am a bit confused about it, would very much appreciate for your help.