-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdns_mass_resolve.py
More file actions
executable file
·43 lines (32 loc) · 965 Bytes
/
Copy pathdns_mass_resolve.py
File metadata and controls
executable file
·43 lines (32 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python
"""Resolve hostnames concurrently, exit after 2 seconds.
This is ported from gevent examples, except it does not use a pool, since there isn't one for gevent2 yet.
"""
from __future__ import with_statement
import sys
import gevent2 as gevent
import traceback
from time import time
import socket
N = 100
finished = 0
def job(domain):
print 'starting', domain
global finished
try:
try:
ip = gevent.getaddrinfo(domain, 'http')
print ('%s = %s' % (domain, ip))
except socket.gaierror:
ex = sys.exc_info()[1]
print ('%s failed with %s' % (domain, ex))
except:
traceback.print_exc()
finally:
finished += 1
start = time()
for x in xrange(10, 10 + N):
gevent.spawn(job, '%s.com' % x)
print 'Spawning took %.2f (%r/%r finished)' % (time() - start, finished, N)
gevent.wait()
print ('finished after 2 seconds: %s/%s' % (finished, N))