How to know if connection is active when using telnetlib?

sp1d3rx at sp1d3rx at
Fri Aug 26 19:19:23 CEST 2005

Well, running this code:
>>> import telnetlib
>>>  c = telnetlib.Telnet("blah")
throws this exception:
socket.gaierror: (11001, 'getaddrinfo failed')
note that this is the same as your "". So, you
will want to use TRY: and EXCEPT: to catch those errors, as in the
example code below...
import telnetlib
    c = telnetlib.Telnet("blah")
except socket.gaierror:
    print "host could not be found."
Note that the "socket.gaierror" is thrown when the hostname is invalid,
and "socket.error" is thrown when the connection is refused. If you try
to perform a "read" operation on a closed socket, you'll get thrown a
"EOFerror" or you may get a Null value.  You'll have to handle each
case. I would suggest referring to the documentation at
"" for more
information about errors / exceptions returned. If there is none
specified, chances are, it will throw a "socket.*" exception, or a Null

More information about the Python-list mailing list