Well, running this code:
----------
import telnetlib
c = telnetlib.Telne t("blah")
----------
throws this exception:
----------
socket.gaierror : (11001, 'getaddrinfo failed')
----------
note that this is the same as your "telnetlib.Teln et.open". So, you
will want to use TRY: and EXCEPT: to catch those errors, as in the
example code below...
----------
import telnetlib
try:
c = telnetlib.Telne t("blah")
except socket.gaierror :
print "host could not be found."
----------
Note that the "socket.gaierro r" is thrown when the hostname is invalid,
and "socket.err or" 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
"http://www.python.org/doc/2.4/lib/telnet-objects.html" for more
information about errors / exceptions returned. If there is none
specified, chances are, it will throw a "socket.*" exception, or a Null
value.