By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

Python telnetlib to openSUSE telnet server problem

P: 1
A test application I wrote uses Python 2.7.11 and telnetlib to connect to telnet servers on test target machines (this test environment is used within a closed lab network for those who may ask 'why not SSH?'). Server targets running Linux Mint 17.2 work fine with this telnet, but the new openSUSE LEAP 42.1 targets need to add fail to run past the telnet login. PuTTY trial sessions operate well to either target type.

The openSUSE targets appear to respond to the telnet logon as expected (if I supply either username or password incorrectly the target responds with 'Login incorrect' and re-asks for login and Password). But beyond a successful login nothing gets responded to, including the simplest 'ls' query.

Simplest test case showing the problem with openSUSE target (works fine for Linux Mint target):
Expand|Select|Wrap|Line Numbers
  1.  import telnetlib
  2. import time
  3.  
  4. host = "172.22.200.235"
  5. username = "lab"
  6. password = "Test"   
  7.  
  8. if __name__ == '__main__': 
  9.     tn = telnetlib.Telnet()    
  10. #    tn.set_debuglevel(1)    
  11.     tn.open(host)
  12.  
  13.     tn.read_until("login:")                  
  14.     tn.write(username + "\n")
  15.  
  16.     tn.read_until("Password:") 
  17.     tn.write(password + "\n") 
  18.  
  19.     for x in range(0,30):
  20.         time.sleep(3)     
  21.         tn.write("ls\n")   
  22.         response = tn.read_very_eager()
  23.         print x, " response: ", response 
Results of running code (with 'set_debuglevel(1)' commented out):
Expand|Select|Wrap|Line Numbers
  1.  0  response:
  2.  
  3. 1  response:
  4. 2  response:
  5. 3  response:
  6. 4  response:
  7. 5  response:
  8. 6  response:
  9. 7  response:
  10. 8  response:
  11. 9  response:  Last login: Mon Apr  4 19:58:44 PDT 2016 from fol-lab-comp03.company-corp.local on pts/3
  12.  
  13. 10  response:
  14. 11  response:
  15. 12  response:
  16. 13  response:
  17. Traceback (most recent call last):
  18.   File "openSUSE.py", line 22, in <module>
  19.     response = tn.read_very_eager()
  20.   File "C:\Python27\lib\telnetlib.py", line 418, in read_very_eager
  21.     return self.read_very_lazy()
  22.   File "C:\Python27\lib\telnetlib.py", line 455, in read_very_lazy
  23.     raise EOFError, 'telnet connection closed'
  24. EOFError: telnet connection closed
And results of running code with the 'set_debuglevel(1)' line included:
Expand|Select|Wrap|Line Numbers
  1.  Telnet(172.22.200.235,23): recv "\xff\xfd\x18\xff\xfd \xff\xfd#\xff\xfd'"
  2. Telnet(172.22.200.235,23): IAC DO 24
  3. Telnet(172.22.200.235,23): IAC DO 32
  4. Telnet(172.22.200.235,23): IAC DO 35
  5. Telnet(172.22.200.235,23): IAC DO 39
  6. Telnet(172.22.200.235,23): recv '\xff\xfb\x03\xff\xfd\x01\xff\xfd\x1f\xff\xfb\x05\xff\xfd!'
  7. Telnet(172.22.200.235,23): IAC WILL 3
  8. Telnet(172.22.200.235,23): IAC DO 1
  9. Telnet(172.22.200.235,23): IAC DO 31
  10. Telnet(172.22.200.235,23): IAC WILL 5
  11. Telnet(172.22.200.235,23): IAC DO 33
  12. Telnet(172.22.200.235,23): recv '\xff\xfb\x03'
  13. Telnet(172.22.200.235,23): IAC WILL 3
  14. Telnet(172.22.200.235,23): recv '\xff\xfb\x01Welcome to openSUSE Leap 42.1 - Kernel 4.1.12-1'
  15. Telnet(172.22.200.235,23): IAC WILL 1
  16. Telnet(172.22.200.235,23): recv '-default (3).\r\n'
  17. Telnet(172.22.200.235,23): recv 'linux-purley9 login: '
  18. Telnet(172.22.200.235,23): send 'lab\n'
  19. Telnet(172.22.200.235,23): recv 'Password: '
  20. Telnet(172.22.200.235,23): send 'Test\n'
  21. Telnet(172.22.200.235,23): send 'ls\n'
  22. Telnet(172.22.200.235,23): recv '\r\n'
  23. 0  response:
  24.  
  25. Telnet(172.22.200.235,23): send 'ls\n'
  26. 1  response:
  27. Telnet(172.22.200.235,23): send 'ls\n'
  28. 2  response:
  29. Telnet(172.22.200.235,23): send 'ls\n'
  30. 3  response:
  31. Telnet(172.22.200.235,23): send 'ls\n'
  32. 4  response:
  33. Telnet(172.22.200.235,23): send 'ls\n'
  34. 5  response:
  35. Telnet(172.22.200.235,23): send 'ls\n'
  36. 6  response:
  37. Telnet(172.22.200.235,23): send 'ls\n'
  38. 7  response:
  39. Telnet(172.22.200.235,23): send 'ls\n'
  40. 8  response:
  41. Telnet(172.22.200.235,23): send 'ls\n'
  42. 9  response:
  43. Telnet(172.22.200.235,23): send 'ls\n'
  44. Telnet(172.22.200.235,23): recv 'Last login: Mon Apr  4 20:00:26 PDT 2016 from fol-'
  45. Telnet(172.22.200.235,23): recv 'lab-comp03.company-corp.local on pts/3\r\n'
  46. 10  response:  Last login: Mon Apr  4 20:00:26 PDT 2016 from fol-lab-comp03.company-corp.local on pts/3
  47.  
  48. Telnet(172.22.200.235,23): send 'ls\n'
  49. 11  response:
  50. Telnet(172.22.200.235,23): send 'ls\n'
  51. 12  response:
  52. Telnet(172.22.200.235,23): send 'ls\n'
  53. 13  response:
  54. Telnet(172.22.200.235,23): send 'ls\n'
  55. Telnet(172.22.200.235,23): recv 'login: timed out after 60 seconds\r\n'
  56. Traceback (most recent call last):
  57.   File "openSUSE.py", line 22, in <module>
  58.     response = tn.read_very_eager()
  59.   File "C:\Python27\lib\telnetlib.py", line 416, in read_very_eager
  60.     self.fill_rawq()
  61.   File "C:\Python27\lib\telnetlib.py", line 576, in fill_rawq
  62.     buf = self.sock.recv(50)
  63. socket.error: [Errno 10053] An established connection was aborted by the software in your host machine

I put the for loop in to illustrate the delay until the login response appears. But then despite sending multiple 'ls' and doing reads the session times out as if it hasn't been contacted [Same result if I only send 'ls' once or use 'read_all()' instead of 'read_very_eager()' -- tried dozens of such things at this point].

Any help much appreciated!
Apr 5 '16 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.