|
|
|
@ -5,22 +5,31 @@ from urllib import request, error
|
|
|
|
|
import socket
|
|
|
|
|
import sys
|
|
|
|
|
target = "http://theresno.cloud/ip"
|
|
|
|
|
prx_api = "http://pubproxy.com/api/proxy?limit=10&http=true&format=txt"
|
|
|
|
|
prx_api = "https://www.proxyscan.io/api/proxy?last_check=9800&limit=10&type=http" #"http://pubproxy.com/api/proxy?limit=10&http=true&format=txt"
|
|
|
|
|
|
|
|
|
|
def get_list_from_api():
|
|
|
|
|
import json
|
|
|
|
|
print('Requesting proxy list... ', end='')
|
|
|
|
|
result = request.urlopen(prx_api)
|
|
|
|
|
prx_list = result.read().decode().split('\n')
|
|
|
|
|
print('Got {} proxies.'.format(len(prx_list)))
|
|
|
|
|
# json magic starts here
|
|
|
|
|
content = result.read().decode()
|
|
|
|
|
json_data = json.loads(content)
|
|
|
|
|
prx_list = ["".join(json_data[i]["Ip"] + ':' + str(json_data[i]["Port"])) for i in range(len(json_data))]
|
|
|
|
|
#= result.read().decode().split('\n')
|
|
|
|
|
print('got {} proxies.'.format(len(prx_list)))
|
|
|
|
|
return prx_list
|
|
|
|
|
|
|
|
|
|
def test_proxy(prx):
|
|
|
|
|
try:
|
|
|
|
|
from http.client import RemoteDisconnected
|
|
|
|
|
except ImportError:
|
|
|
|
|
from httplib import BadStatusLine as RemoteDisconnected
|
|
|
|
|
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, timeout=5)
|
|
|
|
|
result = opener.open(target, timeout=10)
|
|
|
|
|
content = result.read().decode()
|
|
|
|
|
print(srv_string + 'ok. \u2705')
|
|
|
|
|
return True
|
|
|
|
@ -30,9 +39,9 @@ def test_proxy(prx):
|
|
|
|
|
except error.URLError:
|
|
|
|
|
print(srv_string + 'down! \u2935')
|
|
|
|
|
return False
|
|
|
|
|
#except error.RemoteDisconnected:
|
|
|
|
|
# print(srv_string + 'connection fail!')
|
|
|
|
|
# return False
|
|
|
|
|
except RemoteDisconnected:
|
|
|
|
|
print(srv_string + 'connection fail!')
|
|
|
|
|
return False
|
|
|
|
|
except socket.timeout:
|
|
|
|
|
print(srv_string + 'timeout! \u23f3')
|
|
|
|
|
return False
|
|
|
|
|