Python telnetlib client doesn't appear to be opening telnet connection to server -
i trying open telnet connection, write 1 string, print telnet server in python. assume missing obvious because documentation seems pretty self-explanatory , doing think exact same thing in terminal works fine.
here python code:
import telnetlib telnet = telnetlib.telnet() telnet.open('192.168.1.128', 9801, 10) telnet.write("system_cal") print(telnet.read_all())
this times out after 10 seconds / doesn't connect server assume. here output:
traceback (most recent call last): file "/volumes/work/scripting/telnet test/main.py", line 9, in <module> print(telnet.read_all()) file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/telnetlib.py", line 385, in read_all self.fill_rawq() file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/telnetlib.py", line 576, in fill_rawq buf = self.sock.recv(50) socket.timeout: timed out
in image below connect same server in terminal , works fine. @ end give "disconnect" command taken server why connection closes.
am missing something? why working in terminal , not in python?
i suppose sending command early, , receiving end ignoring it. try read banner first:
print(telnet.read_until("welcome.")) telnet.write("system_cal") print(telnet.read_all())
edit:
i note don't have line-terminating sequence @ end of "system_cal". presume that, in interactive session, press ↵ enter after type "system_cal". if case, you'll need add \n
@ end of write()
call:
telnet.write("system_cal\n")
depending upon other factors outside of question, possible may need 1 of following instead:
telnet.write("system_cal\r") telnet.write("system_cal\r\n")
Comments
Post a Comment