title: Python telnetlib and console connection cisco node
body: <p>I am trying to connect to the console connection of a cisco node via a cisco terminal/comm server.
  To do this I telnet to the IP-address of the cisco terminal/comm server on a specific port let us say X.X.X.X - port 2068.
  When I am doing this from my computer via the CLI it looks like this:</p>
  
  <pre><code>[user@computer]$ telnet X.X.X.X 2068
  Trying X.X.X.X...
  Connected to X.X.X.X (X.X.X.X).
  Escape character is '^]'.
  
  Username: &lt;user&gt;
  Password: 
  
  console-cisco-node&gt;
  </code></pre>
  
  <p>So no problem via the CLI on my computer.
  But when I run the below Python code on my computer it does not seem to work ...</p>
  
  <pre><code>#! /usr/bin/env python
  
  import telnetlib
  
  tn = telnetlib.Telnet("X.X.X.X",2068)
  tn.set_debuglevel(8)
  data = tn.read_some()
  tn.close()
  if data == '':
    print 'variable data is EMPTY'
  else:
    print data
    print "variable data is FILLED !!!"
  </code></pre>
  
  <p>When I run this code I only get to see this, it looks like the 'tn.read_some()' just waits forever because nothing is coming from the cisco terminal/comm server ?
  [same for tn.read_all()]</p>
  
  <p>PS. I stopped the running code by hitting CTRL-C</p>
  
  <pre><code>[user@computer]$ ./test.py   
  Telnet(X.X.X.X,2068): recv '\xff\xfb\x01\xff\xfb\x03\xff\xfd\x18\xff\xfd\x1f'
  Telnet(X.X.X.X,2068): IAC WILL 1
  Telnet(X.X.X.X,2068): IAC WILL 3
  Telnet(X.X.X.X,2068): IAC DO 24
  Telnet(X.X.X.X,2068): IAC DO 31
  Telnet(X.X.X.X,2068): recv '\xff\xfc\x01'
  Telnet(X.X.X.X,2068): IAC WONT 1
  Telnet(X.X.X.X,2068): recv '\xff\xfc\x03'
  Telnet(X.X.X.X,2068): IAC WONT 3
  Telnet(X.X.X.X,2068): recv '\xff\xfe\x18'
  Telnet(X.X.X.X,2068): IAC DONT 24
  Telnet(X.X.X.X,2068): recv '\xff\xfe\x1f'
  Telnet(X.X.X.X,2068): IAC DONT 31
  
  Traceback (most recent call last):
    File "./test.py", line 7, in ?
      data = tn.read_some()
    File "/usr/lib64/python2.4/telnetlib.py", line 345, in read_some
      self.fill_rawq()
    File "/usr/lib64/python2.4/telnetlib.py", line 521, in fill_rawq
      buf = self.sock.recv(50)
  KeyboardInterrupt
  </code></pre>
  
  <p>When I change the 'tn.read_some()' in the code to 'tn.read_eager()' or 'tn.read_very_eager()' or 'tn.read_lazy()' or 'tn.read_very_lazy()' and run the code again it shows me this:</p>
  
  <pre><code>[user@computer]$ ./test.py
  variable data is EMPTY
  </code></pre>
  
  <p>When I change the python code to connect not to the console connection of the cisco node but to the management connection of the cisco node (another IP-address Y.Y.Y.Y on normal port 23) as follows it works just fine, I see this output:</p>
  
  <pre><code>[user@computer]$ ./test1.py 
  Telnet(Y.Y.Y.Y,23): recv '\xff\xfb\x01\xff\xfb\x03\xff\xfd\x18\xff\xfd\x1f'
  Telnet(Y.Y.Y.Y,23): IAC WILL 1
  Telnet(Y.Y.Y.Y,23): IAC WILL 3
  Telnet(Y.Y.Y.Y,23): IAC DO 24
  Telnet(Y.Y.Y.Y,23): IAC DO 31
  Telnet(Y.Y.Y.Y,23): recv '\r\n************************************************'
  
  ************************************************
  variable data is FILLED !!!
  </code></pre>
  
  <p>So the Python code is OK I think.
  It is just that the cisco terminal/COMM server (X.X.X.X) is reacting in such a different way then normal that Python telnetlib is confused I think.</p>
  
  <p>Anyone out there experienced something simular ?</p>