Python telnetlib to openSUSE telnet server problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JeffK58790873
    New Member
    • Apr 2016
    • 1

    Python telnetlib to openSUSE telnet server problem

    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):
    Code:
     import telnetlib
    import time
    
    host = "172.22.200.235"
    username = "lab"
    password = "Test"   
     
    if __name__ == '__main__': 
        tn = telnetlib.Telnet()    
    #    tn.set_debuglevel(1)    
        tn.open(host)
        
        tn.read_until("login:")                  
        tn.write(username + "\n")
        
        tn.read_until("Password:") 
        tn.write(password + "\n") 
        
        for x in range(0,30):
            time.sleep(3)     
            tn.write("ls\n")   
            response = tn.read_very_eager()
            print x, " response: ", response
    Results of running code (with 'set_debuglevel (1)' commented out):
    Code:
     0  response:
    
    1  response:
    2  response:
    3  response:
    4  response:
    5  response:
    6  response:
    7  response:
    8  response:
    9  response:  Last login: Mon Apr  4 19:58:44 PDT 2016 from fol-lab-comp03.company-corp.local on pts/3
    
    10  response:
    11  response:
    12  response:
    13  response:
    Traceback (most recent call last):
      File "openSUSE.py", line 22, in <module>
        response = tn.read_very_eager()
      File "C:\Python27\lib\telnetlib.py", line 418, in read_very_eager
        return self.read_very_lazy()
      File "C:\Python27\lib\telnetlib.py", line 455, in read_very_lazy
        raise EOFError, 'telnet connection closed'
    EOFError: telnet connection closed
    And results of running code with the 'set_debuglevel (1)' line included:
    Code:
     Telnet(172.22.200.235,23): recv "\xff\xfd\x18\xff\xfd \xff\xfd#\xff\xfd'"
    Telnet(172.22.200.235,23): IAC DO 24
    Telnet(172.22.200.235,23): IAC DO 32
    Telnet(172.22.200.235,23): IAC DO 35
    Telnet(172.22.200.235,23): IAC DO 39
    Telnet(172.22.200.235,23): recv '\xff\xfb\x03\xff\xfd\x01\xff\xfd\x1f\xff\xfb\x05\xff\xfd!'
    Telnet(172.22.200.235,23): IAC WILL 3
    Telnet(172.22.200.235,23): IAC DO 1
    Telnet(172.22.200.235,23): IAC DO 31
    Telnet(172.22.200.235,23): IAC WILL 5
    Telnet(172.22.200.235,23): IAC DO 33
    Telnet(172.22.200.235,23): recv '\xff\xfb\x03'
    Telnet(172.22.200.235,23): IAC WILL 3
    Telnet(172.22.200.235,23): recv '\xff\xfb\x01Welcome to openSUSE Leap 42.1 - Kernel 4.1.12-1'
    Telnet(172.22.200.235,23): IAC WILL 1
    Telnet(172.22.200.235,23): recv '-default (3).\r\n'
    Telnet(172.22.200.235,23): recv 'linux-purley9 login: '
    Telnet(172.22.200.235,23): send 'lab\n'
    Telnet(172.22.200.235,23): recv 'Password: '
    Telnet(172.22.200.235,23): send 'Test\n'
    Telnet(172.22.200.235,23): send 'ls\n'
    Telnet(172.22.200.235,23): recv '\r\n'
    0  response:
    
    Telnet(172.22.200.235,23): send 'ls\n'
    1  response:
    Telnet(172.22.200.235,23): send 'ls\n'
    2  response:
    Telnet(172.22.200.235,23): send 'ls\n'
    3  response:
    Telnet(172.22.200.235,23): send 'ls\n'
    4  response:
    Telnet(172.22.200.235,23): send 'ls\n'
    5  response:
    Telnet(172.22.200.235,23): send 'ls\n'
    6  response:
    Telnet(172.22.200.235,23): send 'ls\n'
    7  response:
    Telnet(172.22.200.235,23): send 'ls\n'
    8  response:
    Telnet(172.22.200.235,23): send 'ls\n'
    9  response:
    Telnet(172.22.200.235,23): send 'ls\n'
    Telnet(172.22.200.235,23): recv 'Last login: Mon Apr  4 20:00:26 PDT 2016 from fol-'
    Telnet(172.22.200.235,23): recv 'lab-comp03.company-corp.local on pts/3\r\n'
    10  response:  Last login: Mon Apr  4 20:00:26 PDT 2016 from fol-lab-comp03.company-corp.local on pts/3
    
    Telnet(172.22.200.235,23): send 'ls\n'
    11  response:
    Telnet(172.22.200.235,23): send 'ls\n'
    12  response:
    Telnet(172.22.200.235,23): send 'ls\n'
    13  response:
    Telnet(172.22.200.235,23): send 'ls\n'
    Telnet(172.22.200.235,23): recv 'login: timed out after 60 seconds\r\n'
    Traceback (most recent call last):
      File "openSUSE.py", line 22, in <module>
        response = tn.read_very_eager()
      File "C:\Python27\lib\telnetlib.py", line 416, in read_very_eager
        self.fill_rawq()
      File "C:\Python27\lib\telnetlib.py", line 576, in fill_rawq
        buf = self.sock.recv(50)
    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_eage r()' -- tried dozens of such things at this point].

    Any help much appreciated!
Working...