Speed up with threads
Rhymes
raims at dot.com
Sat Aug 3 05:07:27 EDT 2002
I've written a simple portscanner (two version: the first without
threads and the second one with threads). I just want to speed up more
the scanning, what can i do?
----------- code snippets -----------------
# this is a reasonable limit.
MAX_THREADS = 50
# it's the inherited run() method of the scanner class
# (inherits threading.Thread)
def run(self):
try:
# connect to the given host:port
self.sd.connect((self.host, self.port))
print "%s:%d OPEN" % (self.host, self.port)
self.sd.close()
except: pass
# the scan method of the main class
def scan(self, host, start, stop):
self.port = start
while self.port < stop:
while threading.activeCount() < MAX_THREADS:
Scanner(host, self.port).start()
self.port = self.port + 1
--
Rhymes (rhymes at myself.com)
http://www26.brinkster.com/rhymes
" ride or die "
More information about the Python-list
mailing list