nicer output
This commit is contained in:
parent
998a0ea8f2
commit
9056ca5a4d
27
panxy.py
27
panxy.py
@ -7,29 +7,42 @@ target = "http://theresno.cloud/ip"
|
||||
prx_api = "http://pubproxy.com/api/proxy?limit=10&http=true&format=txt"
|
||||
|
||||
def get_list():
|
||||
print('Requesting proxy list...')
|
||||
result = request.urlopen(prx_api)
|
||||
prx_list = result.read().decode()
|
||||
return prx_list.split('\n')
|
||||
prx_list = result.read().decode().split('\n')
|
||||
print('Got {} proxies.'.format(len(prx_list)))
|
||||
return prx_list
|
||||
|
||||
def test_proxy(prx):
|
||||
print("Testing proxy " + prx + "... ", end='')
|
||||
srv_string = "Testing proxy " + prx + "... "
|
||||
print(srv_string, end='\r')
|
||||
proxy_handler = request.ProxyHandler({'https': 'http://' + prx + '/', 'http': 'http://' + prx + '/' })
|
||||
opener = request.build_opener(proxy_handler)
|
||||
try:
|
||||
result = opener.open(target)
|
||||
content = result.read().decode()
|
||||
print('ok.')
|
||||
print(srv_string + 'ok.')
|
||||
return True
|
||||
except error.HTTPError:
|
||||
print('fail.')
|
||||
print(srv_string + 'fail.')
|
||||
return False
|
||||
#except RemoteDisconnected:
|
||||
# print('fail.')
|
||||
except error.URLError:
|
||||
print('down!')
|
||||
print(srv_string + 'down!')
|
||||
return False
|
||||
|
||||
def main():
|
||||
|
||||
proxy_list = get_list()
|
||||
working_list = []
|
||||
start_length = len(proxy_list)
|
||||
for entry in proxy_list:
|
||||
test_proxy(entry)
|
||||
if test_proxy(entry):
|
||||
working_list.append(entry)
|
||||
else:
|
||||
pass
|
||||
print('{}/{} proxies ready.'.format(len(working_list), start_length))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user