forked from shell909090/antigfw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgfw_tester
executable file
·52 lines (45 loc) · 1.43 KB
/
gfw_tester
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
@date: 2012-05-07
@author: shell.xu
'''
import sys, urllib, getopt
from gevent import monkey, pool, Timeout
monkey.patch_all()
pool = pool.Pool(1000)
rslt = []
def download_gfwlist():
url = 'https://github.com/shell909090/antigfw/raw/master/uniproxy/gfw'
sys.stdout.write(urllib.urlopen(url).read())
def test_domain(do):
do = do.strip()
try:
for sch in ['http', 'https']:
with Timeout(60, Exception) as timeout:
if urllib.urlopen('%s://%s' % (sch, do),
proxies={}).getcode() == 200:
if '-f' not in optdict:
print '%s passed with %s' % (do, sch)
rslt.append(do)
return True
except Exception: pass
return False
def filter_file(filepath):
with open(filepath, 'r') as fi:
r = [line for line in fi if line.strip() not in rslt]
with open(filepath, 'w') as fo:
for line in r: fo.write(line)
def gfw_tester(args):
for filepath in args:
with open(filepath, 'r') as fi: pool.map(test_domain, fi)
pool.join()
if '-f' in optdict:
for filepath in args: filter_file(filepath)
def main():
global optdict
optlist, args = getopt.getopt(sys.argv[1:], 'fd')
optdict = dict(optlist)
if '-d' in optdict: download_gfwlist()
else: gfw_tester(args)
if __name__ == "__main__": main()