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

This commit is contained in:
Felix Pankratz 2020-03-24 21:50:13 +01:00
parent 4015b9b891
commit 998a0ea8f2

View File

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