forked from yhangf/PythonCrawler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxyip.py
More file actions
50 lines (40 loc) · 1.21 KB
/
proxyip.py
File metadata and controls
50 lines (40 loc) · 1.21 KB
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
import requests
import threading
import re
enableips = []
class IsEnable(threading.Thread):
def __init__(self, ip):
super(IsEnable, self).__init__()
self.ip = ip
self.proxies = {
'http': 'http://%s' % ip
}
def run(self):
global enableips
try:
html = requests.get('http://httpbin.org/ip', proxies=self.proxies, timeout=5).text
result = eval(html)['origin']
if result in self.ip:
enableips.append(self.ip)
except:
return False
def parser(url):
html = requests.get(url).text
ips = re.findall('\d+\.\d+\.\d+\.\d+:\d+', html)
return ips
def get_enableips():
global enableips
urls = ['http://proxy.ipcn.org/proxya.html', 'http://proxy.ipcn.org/proxya2.html',
'http://proxy.ipcn.org/proxyb.html', 'http://proxy.ipcn.org/proxyb2.html']
for url in urls:
ips = parser(url)
threadings = []
for ip in ips:
work = IsEnable(ip)
work.setDaemon(True)
threadings.append(work)
for work in threadings:
work.start()
for work in threadings:
work.join()
return enableips