import urllib import urllib2 import socket from threadpool import Thre

 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import urllib
import urllib2
import socket
from threadpool import ThreadPool, makeRequests
from Queue import Queue
def find_key(key, data, unique=True):
values = []
for x in data.splitlines():
if x.strip():
iter_key, value = x.strip().split(':', 1)
if iter_key == key:
values.append(value)
return values[0] if unique else values
def find_value(value, data, unique=False):
keys = []
for x in data.splitlines():
if x.strip():
key, iter_value = x.strip().split(':', 1)
if iter_value == value:
keys.append(keys)
return keys[0] if unique else keys
def check_task(item):
proxy_handler = urllib2.ProxyHandler({'http': 'http://' + item})
opener = urllib2.build_opener(proxy_handler)
try:
data = opener.open(check_url, post_data).read()
except Exception, ex:
result = item, 'BAD', ex
else:
keys = find_value(ip, data)
if keys:
result = item, 'NOT ANON', ','.join(keys)
else:
result = item, 'ANON', 'REMOTE_ADDR: %s' % find_key('REMOTE_ADDR', data)
print result
#q.put(result)
items = [x.strip() for x in file('list')]
post_data = urllib.urlencode({'foo': 'bar'})
check_url = 'http://it-omsk.com/check.php'
timeout = 5
pool_size = 50
socket.setdefaulttimeout(5)
data = urllib.urlopen(check_url).read()
ip = find_key('REMOTE_ADDR', data)
print 'Your ip: %s' % ip
#q = Queue()
pool = ThreadPool(pool_size)
requests = makeRequests(check_task, items)
[pool.putRequest(x) for x in requests]
pool.wait()
#while not q.empty():
#print q.get()