get proxy list and test entries, needs more error handling :(

master
Felix Pankratz 5 years ago
parent 4015b9b891
commit 998a0ea8f2

@ -1,17 +1,35 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# panxy, a random proxy connector # panxy, a random proxy connector
from urllib import request from urllib import request, error
import sys import sys
target = "http://theresno.cloud/ip" target = "http://theresno.cloud/ip"
prx_api = "http://pubproxy.com/api/proxy?limit=10&http=true&format=txt"
prx = sys.argv[1] def get_list():
print("Using proxy " + prx + " ...") result = request.urlopen(prx_api)
proxy_handler = request.ProxyHandler({'https': 'http://' + prx + '/', 'http': 'http://' + prx + '/' }) prx_list = result.read().decode()
return prx_list.split('\n')
opener = request.build_opener(proxy_handler) def test_proxy(prx):
result = opener.open(target) print("Testing proxy " + prx + "... ", end='')
content = result.read().decode() 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.')
except error.HTTPError:
print('fail.')
#except RemoteDisconnected:
# print('fail.')
except error.URLError:
print('down!')
print(content) def main():
proxy_list = get_list()
for entry in proxy_list:
test_proxy(entry)
if __name__ == '__main__':
main()

Loading…
Cancel
Save