Created
September 23, 2014 17:01
-
-
Save zakird/249487cd692a809db8c5 to your computer and use it in GitHub Desktop.
ast lookup of
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os.path | |
import os | |
import subprocess | |
import sys | |
import logging | |
import multiprocessing | |
from multiprocessing import Pool | |
import time | |
import socket | |
# alexa domains are at http://s3.amazonaws.com/alexa-static/top-1m.csv.zip | |
PROCESS_PROCESSES = 500 | |
def lookup(name): | |
try: | |
print "%s,%s" % (name, socket.gethostbyname(name)) | |
except: | |
pass | |
pool = Pool(PROCESS_PROCESSES) | |
if __name__ == '__main__': | |
results = [] | |
for line in open(sys.argv[1]): | |
domain = line.rstrip().split(",")[1] | |
results.append(pool.apply_async(lookup, [domain,])) | |
for res in results: | |
while 1: | |
sys.stdout.flush() | |
try: | |
res.get(10) | |
break | |
except multiprocessing.TimeoutError: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment