You need to use a try...except
block to catch the exception and tell the interpreter to ignore it. For example:
import socket
for i in range(len(HOST)):
print "scanning " + HOST[i] + " ...\n"
try:
tn = telnetlib.Telnet(HOST[i],23,3)
except socket.timeout:
pass
In this case it's a good idea to explicitly state which exception you want to catch (socket.timeout
). Sockets can throw many different types of exceptions so using a generic except:
statement might mask a problem with opening, reading or writing to the socket.