-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpike_hqpeak.py
48 lines (36 loc) · 1.02 KB
/
pike_hqpeak.py
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
import requests
import json
from multiprocessing.dummy import Pool as ThreadPool
THREADS = 1000
TEST_URL = 'http://canihazip.com/s'
PROXY_PORTS = [8080, 45554, 3128, 1080, 80, 8888]
pool = ThreadPool(THREADS)
r = requests.get('http://pike.hqpeak.com/api/proxy').json()
proxies = []
for ip in r:
for port in PROXY_PORTS:
proxies.append(ip + ':' + str(port))
print(proxies)
count = 0
def check_proxy(proxy):
global count
count += 1
print(count, len(proxies))
_proxies = {
'http': 'http://' + proxy,
'https': 'https://' + proxy
}
try:
r = requests.get(TEST_URL, proxies=_proxies, timeout=5)
return { 'proxy': proxy, 'working': True }
except Exception as e:
print(e)
return { 'proxy': proxy, 'working': False }
results = pool.map(check_proxy, proxies)
working = []
for result in results:
if result['working']:
working.append(result['proxy'])
with open('working.txt', 'w') as f:
for proxy in working:
f.write(proxy + '\n')