0

I am trying to use telnet to get some information back from a machine, and this is what I doing. from windows in putty I set it up to be telnet, put the ip and the port, and connect, I do get the console where it say:

Type the hot key to suspend the connection: Z and the cursor is blinking at the beginning of the next line. I hit enter in the keyboard. and I can start typing commands like ls.

my code is very simple. since there is no or password

import telnetlib
tn = telnetlib.Telnet("10.35.180.239", port=7033)
tn.write("\n")
#n.write("vt102\n") # we might need to tell the type of console?
tn.write("ls\n")
print tn.read_all()
tn.close()

some one mention in this link telnetlib python example that we needed to write the type of console we are using, but I didn't get a diferent outcome.

this is what I get in my console.

ls

This connection is in use. User(s) currently connected: NONE@440.
You need privilege to make a simultaneous session.

may I be missing some steps? or there is something magical that needs to bet set up?

thank you guys.

Community
  • 1
  • 1
pelos
  • 1,744
  • 4
  • 24
  • 34
  • Are you sure you can establish a telnet connection ? add a timeout or check if Telnet returns you a telnet object. The error points that somebody else is also connected to the machine , how many simultaneous telnet sessions does this "Machine" allow ? Also you need to wait for a promt after any write to a session tn.write should be followed by ether read_until() or expect() read_all() calls or else the subsequent write calls will be too fast to run – cmidi Feb 20 '15 at 22:34
  • I am doing the code on the same machine that I am testing with putty. import telnetlib tn = telnetlib.Telnet("10.35.180.239", port=7016, timeout=5) print tn and I get that's how should I be cheking it right? – pelos Feb 20 '15 at 22:53
  • Correct. you might want to add a expect()/read_all() call in between each write something on the lines of `tn.expect("#\n",timeout=5)` use `index,obj,read= tn.expect("#\n",timeout=5)` in case you want the return output until the expected string the read variable contains the read output. One way to debug telnet issues is to enable debugging which can be done by `tn.set_debuglevel(1)` did you try that ? – cmidi Feb 20 '15 at 23:00
  • Having said all this my question still is does the machine you are testing allows mutiple telnet sessions. You can test it manually first by trying multiple telnet sessions to the same machine. – cmidi Feb 20 '15 at 23:10

0 Answers0