nicer output

master
Felix Pankratz 5 years ago
parent 998a0ea8f2
commit 9056ca5a4d

@ -7,29 +7,42 @@ target = "http://theresno.cloud/ip"
prx_api = "http://pubproxy.com/api/proxy?limit=10&http=true&format=txt" prx_api = "http://pubproxy.com/api/proxy?limit=10&http=true&format=txt"
def get_list(): def get_list():
print('Requesting proxy list...')
result = request.urlopen(prx_api) result = request.urlopen(prx_api)
prx_list = result.read().decode() prx_list = result.read().decode().split('\n')
return prx_list.split('\n') print('Got {} proxies.'.format(len(prx_list)))
return prx_list
def test_proxy(prx): 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 + '/' }) proxy_handler = request.ProxyHandler({'https': 'http://' + prx + '/', 'http': 'http://' + prx + '/' })
opener = request.build_opener(proxy_handler) opener = request.build_opener(proxy_handler)
try: try:
result = opener.open(target) result = opener.open(target)
content = result.read().decode() content = result.read().decode()
print('ok.') print(srv_string + 'ok.')
return True
except error.HTTPError: except error.HTTPError:
print('fail.') print(srv_string + 'fail.')
return False
#except RemoteDisconnected: #except RemoteDisconnected:
# print('fail.') # print('fail.')
except error.URLError: except error.URLError:
print('down!') print(srv_string + 'down!')
return False
def main(): def main():
proxy_list = get_list() proxy_list = get_list()
working_list = []
start_length = len(proxy_list)
for entry in 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__': if __name__ == '__main__':
main() main()

Loading…
Cancel
Save