-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
135 lines (102 loc) · 3.56 KB
/
test.py
File metadata and controls
135 lines (102 loc) · 3.56 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import proxymanager
import hidemyass
import fpl
import sys
import requests
def test_proxy(proxy):
attempts = 0
http_result = test_http(proxy)
https_result = test_https(proxy)
return http_result, https_result
def test_http(proxy):
attempts = 0
proxy_string = 'http://'+proxy.get_ip()+':'+proxy.get_port()
print('HTTP test for \'{}\''.format(proxy_string))
while attempts < 3:
s = requests.Session()
url = 'http://ya.ru'
s.proxies = { 'http': proxy_string }
try:
r = s.get(url, timeout = 10)
if r.status_code == 200:
return True
except:
print('Exception on GET request: ', sys.exc_info()[0])
pass
attempts += 1
return False
def test_https(proxy):
attempts = 0
proxy_string = 'https://'+proxy.get_ip()+':'+proxy.get_port()
print('HTTPS test for \'{}\''.format(proxy_string))
while attempts < 3:
s = requests.Session()
url = 'https://ya.ru'
s.proxies = { 'https': proxy_string }
try:
r = s.get(url, timeout = 10)
if r.status_code == 200:
return True
except:
print('Exception on GET request: ', sys.exc_info()[0])
pass
attempts += 1
return False
def test_provider(provider):
working = 0
failed = 0
proxy_manager = proxymanager.ProxyManager()
proxy_manager.add_proxy_provider(provider)
proxy_manager.update_proxy_list()
while True:
proxy = proxy_manager.get_proxy()
if proxy is None:
break
print('Testing: ' + proxy.get_ip() + ':' + proxy.get_port() + ' ( ' + proxy.get_type() + ' )' )
http_result, https_result = test_proxy(proxy)
print (' HTTP: ' + ' OK' if http_result else 'FAILED')
print (' HTTPS: ' + ' OK' if https_result else 'FAILED')
if http_result or https_result:
working += 1
else:
failed += 1
return working, failed
class ProviderTest:
def __init__(self, name, provider):
self._name = name
self._provider = provider
def run_test(self):
print('Running tests for : ' + self._name)
print('')
self._working = 0
self._failed = 0
proxy_manager = proxymanager.ProxyManager()
proxy_manager.add_proxy_provider(self._provider)
proxy_manager.update_proxy_list()
while True:
proxy = proxy_manager.get_proxy()
if proxy is None:
break
print('Testing: ' + proxy.get_ip() + ':' + proxy.get_port() + ' ( ' + proxy.get_type() + ' )' )
http_result, https_result = test_proxy(proxy)
print (' HTTP: ' + ' OK' if http_result else 'FAILED')
print (' HTTPS: ' + ' OK' if https_result else 'FAILED')
if http_result or https_result:
self._working += 1
else:
self._failed += 1
def __str__(self):
return ''.join( [self._name, ' test results\n', ' Working : ', str(self._working), '\n Failed : ', str(self._failed) ] )
def main():
tests = [ ProviderTest('HideMyAss', hidemyass.ProxyProvider()),
# ProviderTest('FPL', fpl.FPLProxyProvider()),
# ProviderTest('SSL', fpl.SSLProxyProvider()),
# ProviderTest('US', fpl.USProxyProvider()),
# ProviderTest('UK', fpl.UKProxyProvider())
]
for t in tests:
t.run_test()
for t in tests:
print(t)
if __name__ == '__main__':
main()