On Fri, Oct 24, 2008 at 2:33 PM, asit <[EMAIL PROTECTED]> wrote: > this the o/p > [EMAIL PROTECTED]:~/hack$ python portscan.py 59.93.128.10 10 20 > Traceback (most recent call last): > File "portscan.py", line 33, in <module> > print str(port) + " : " + scan(ip,port,timeout) > File "portscan.py", line 22, in scan > return status[result] > KeyError: 11 > [EMAIL PROTECTED]:~/hack$
Oh, connect_ex is returning errno 11, which isn't in your dictionary of statuses. Did you think that the eight items in your status dictionary were the only possible return values of connect_ex? Since the socket module is a thin wrapper over the c socket library, you'll probably need to consult the documentation for that to see exactly what's going on. I'd start with "man connect" on your unix command line, or this page: http://www.opengroup.org/onlinepubs/009695399/functions/connect.html You'd probably be better off using built in modules to map errno to a message, like this: from socket import * import os def scan(ip, port, timeout): s = socket(AF_INET, SOCK_STREAM) s.settimeout(timeout) errno = s.connect_ex((ip, port)) return os.strerror(errno) -- Jerry -- http://mail.python.org/mailman/listinfo/python-list