#!/usr/bin/python import threading from socket import gethostbyname_ex easyadns_debug = False # Enable/disable debugging messages. _names_lock = threading.Lock() _ips_lock = threading.Lock() def _lookup(id, names, ips): while names: if easyadns_debug: print "[%3d] - Getting name..." % id _names_lock.acquire() name = names.pop() _names_lock.release() name = name.strip() if name: if easyadns_debug: print "[%3d] - Doing lookup" % id try: res = gethostbyname_ex(name) # Do lookup except: if easyadns_debug: print "[%3d] - Could not find: %s" % (id, name) continue # Add results to dataset _ips_lock.acquire() for ip in res[2]: ips.add(ip) _ips_lock.release() if easyadns_debug: print "[%s] - Done" % name if easyadns_debug: print "Thread [%d] Done" % id data = set() threads = list() names = open('proxies.txt').readlines() for i in range(0, 50): t = threading.Thread(target=_lookup, args=(i, names, data)) t.start() threads.append(t) if easyadns_debug: print "Done starting %d threads" % len(threads) for t in threads: t.join() if easyadns_debug: print "Last thread exited"