threads/sockets quick question.

n00m n00m at narod.ru
Mon Sep 19 09:10:29 EDT 2005


import socket
import thread

def scan(ip, port):
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((ip, port))
        s.close()
        print '%s | %d OPEN \nscanned: %d' % (ip, port, port)
    except:
        pass

ip = 'localhost'
for port in range(50, 5000):
    thread.start_new_thread(scan, (ip, port,))



This is the output on my machine:

>>>
>>>
localhost | 135 OPEN
scanned: 135

Traceback (most recent call last):
  File "E:/*******.py", line 16, in -toplevel-
    thread.start_new_thread(scan, (ip, port))
error: can't start new thread

>>> localhost | 1027 OPEN
scanned: 1027
localhost | 1029 OPEN
scanned: 1029


>>>
>>>
>>>

Btw I don't understand why many many the threads failed to start.
My box is quite powerful.




More information about the Python-list mailing list