0

I am trying to telnet to a device with ip.

import telnetlib
deviceIp = '192.168.1.135'
password1='xxxxxx'
telnetConeection = telnetlib.Telnet(deviceIp,23)
telnetConeection.read_until(b'Password: ')
telnetConeection.write(password1.encode('ascii') + b"\n")
telnetConeection.write(b'\n')
telnetConeection.write(b'port\n')
print(telnetConeection.read_all())

The ouput as : b'Timeout!\n'

It is clear that :-

  • the connection to device is made
  • the script is reading till 'Password'

What is not clear to me is that :why the write password is not working and timeout is happening? Kindly help me out.

Any suggestion will be highly appreciated !

petezurich
  • 9,280
  • 9
  • 43
  • 57
Archiac Coder
  • 156
  • 2
  • 13
  • So password comes up or not? Are you sure you have the port open (`23`)? – l'L'l Jan 21 '19 at 19:55
  • Yes when I am executing telnet 192.168.1.135 23 on terminal ,it is working fine ! The output is : b'Timeout!\n' on executing above – Archiac Coder Jan 21 '19 at 20:00
  • Can you post the connection log perhaps? – l'L'l Jan 21 '19 at 20:02
  • sorry! did not implement any logging here though !sorry for the inconvenience – Archiac Coder Jan 21 '19 at 20:11
  • I would imagine it's something basic in the script causing the timeout; which platform are you attempting to run this on? Maybe [try this script](https://gist.github.com/ParityError/b5ccb82559c932543e83c406b92fabee) and see if you can successfully connect (it reveals very useful debugging information), to use (`python telnetlib.py -d "hostname"`) – l'L'l Jan 21 '19 at 21:01
  • Thank you for your valuable response! I am using Ubuntu 18.04. The above script you mentioned has hanged since executing it quite some time ago!It's hanged still ! no response – Archiac Coder Jan 21 '19 at 21:20
  • You’re welcome! To determine if it’s a host or client side issue maybe try another telnet host such as “rainmaker.wunderground.com” to see if it will connect. – l'L'l Jan 21 '19 at 21:23
  • Hi,the host you mentioned was not working for me.But,I successfully got response from india.colorado.edu port 13 (the time as the response) through python – Archiac Coder Jan 21 '19 at 21:44

1 Answers1

0

I don't suppose the answer is as simple as increasing your timeout? Maybe the other end is slow?

timeout=30
telnetConeection.read_until(b'Password: ', timeout)

Also, you should probably double check everything the other end is sending you. Maybe the other end isn't even sending you anything (which would point to a different problem). Looks like you've tested that and you're getting what you expect.

ALSO, Telnet.expect might give you more information on your errors (ie EOF? Nothing matched?)

Will Lyles
  • 326
  • 2
  • 6