forked from luzixiaohua/hola_proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhola_proxy.py
More file actions
91 lines (81 loc) · 2.8 KB
/
hola_proxy.py
File metadata and controls
91 lines (81 loc) · 2.8 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#-*- coding:utf-8 -*-
import urllib2
import json
import time
from geoip import geolite2
from requests.auth import HTTPProxyAuth
class HolaProxy():
def __init__(self, username, password, session, country=None, dns=None, servercountry=None):
self.base = 1
self.usename = username
self.password = password
self.session = session
self.country = country
self.dns = dns
self.servercountry = servercountry
self.generate_proxy()
def generate_proxy_auth(self):
username = ''
username_prifix = 'lum-customer-%s-zone-gen' % self.username
username += username_prifix
if self.country:
username += '-country-%s' % self.country
if self.dns:
username += '-dns-%s' % self.dns
proxy_session_tag = 'sid%s_%s' % (self.session, self.base)
username += '-session-%s' % proxy_session_tag
authentication_code = self.password
self.proxy_auth = HTTPProxyAuth(username, authentication_code)
def generate_proxy(self):
self.generate_proxy_auth()
hola_proxy_suffix = '45.55.206.5:22225'
proxy = ''
if self.servercountry:
proxy += 'servercountry-%s.' % self.servercountry
self.proxy = 'http://' + proxy + hola_proxy_suffix
def refresh(self):
self.base += 1
self.generate_proxy()
@property
def remote(self):
return self.proxy
def ping(self):
opener = urllib2.build_opener(urllib2.ProxyHandler({'http': self.remote}))
try:
t0 = time.time()
req = urllib2.Request('http://lumtest.com/myip')
r = opener.open(req, timeout=10)
ip = r.read().strip()
match = geolite2.lookup(ip)
ttl = time.time() - t0
r.close()
return {
'status': 'ok',
'result': {
'ip': ip,
'ttl': ttl,
'country': match.country,
'str': self.remote
}
}
except Exception, e:
return {'status': 'error', 'result': repr(e), 'proxy': str(self.remote)}
if __name__ == '__main__':
import threading
stats = {}
def test_hola(th):
session = th
proxy = HolaProxy(session, country='cn')
for i in range(100):
ping_resp = proxy.ping()
if ping_resp['status'] == 'ok':
if ping_resp['result']['ip'] not in stats:
stats[ping_resp['result']['ip']] = set()
stats[ping_resp['result']['ip']].add(th)
threads = []
for th in range(10):
t = threading.Thread(target=test_hola, args=(th,))
t.start()
threads.append(t)
for t in threads:
t.join()