Skip to content

Instantly share code, notes, and snippets.

@zakird
Created September 23, 2014 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zakird/249487cd692a809db8c5 to your computer and use it in GitHub Desktop.
Save zakird/249487cd692a809db8c5 to your computer and use it in GitHub Desktop.
ast lookup of
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