[Tutor] Basic telnet question
Phil
phil_lor at bigpond.com
Sat Sep 24 05:21:54 EDT 2016
Thank you for reading this.
If I enter the following at the prompt:
$ telnet localhost 7356
The client then responds with:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
I'd like to do the same from Python. My code is as follows:
import telnetlib
tn = telnetlib.Telnet("127.0.0.1", 7356)
print(tn.read_all())
Then, once a connection is established send the character "f"
tn.write("f" + "\n")
print(tn.read_all())
The problem is that the client is not responding, certainly not as
expected. There aren't any Python errors either, however, the console is
blocked until the client is disabled. If I then attempt a connection
with the disabled client a Python connection refused error is displayed,
as I would expect.
I have read the telnetlib document and searched for examples but I seem
to be stuck on a very basic problem.
By the way, I'm using Python 3.5 under Linux.
--
Regards,
Phil
More information about the Tutor
mailing list