├── README.md ├── proxy_check.py ├── proxy_checkpy3.py └── proxy_checkpy3-async.py /README.md: -------------------------------------------------------------------------------- 1 | proxy-checker 2 | ============= 3 | A simple python script to check if a proxy is working. 4 | 5 | Simply put proxy:port in array. If you want to check if internet is working or not, leave the array empty. 6 | -------------------------------------------------------------------------------- /proxy_check.py: -------------------------------------------------------------------------------- 1 | import urllib2, socket 2 | 3 | socket.setdefaulttimeout(180) 4 | 5 | # read the list of proxy IPs in proxyList 6 | proxyList = ['172.30.1.1:8080', '172.30.3.3:8080'] # there are two sample proxy ip 7 | 8 | def is_bad_proxy(pip): 9 | try: 10 | proxy_handler = urllib2.ProxyHandler({'http': pip}) 11 | opener = urllib2.build_opener(proxy_handler) 12 | opener.addheaders = [('User-agent', 'Mozilla/5.0')] 13 | urllib2.install_opener(opener) 14 | req=urllib2.Request('http://www.google.com') # change the url address here 15 | sock=urllib2.urlopen(req) 16 | except urllib2.HTTPError, e: 17 | print 'Error code: ', e.code 18 | return e.code 19 | except Exception, detail: 20 | 21 | print "ERROR:", detail 22 | return 1 23 | return 0 24 | 25 | for item in proxyList: 26 | if is_bad_proxy(item): 27 | print "Bad Proxy", item 28 | else: 29 | print item, "is working" 30 | -------------------------------------------------------------------------------- /proxy_checkpy3.py: -------------------------------------------------------------------------------- 1 | 2 | import urllib.request , socket 3 | 4 | socket.setdefaulttimeout(180) 5 | 6 | # read the list of proxy IPs in proxyList 7 | proxyList = ['140.82.61.218:8080'] # there are two sample proxy ip 8 | 9 | def is_bad_proxy(pip): 10 | try: 11 | proxy_handler = urllib.request.ProxyHandler({'http': pip}) 12 | opener = urllib.request.build_opener(proxy_handler) 13 | opener.addheaders = [('User-agent', 'Mozilla/5.0')] 14 | urllib.request.install_opener(opener) 15 | sock=urllib.request.urlopen('http://www.google.com') # change the url address here 16 | #sock=urllib.urlopen(req) 17 | except urllib.error.HTTPError as e: 18 | print('Error code: ', e.code) 19 | return e.code 20 | except Exception as detail: 21 | 22 | print( "ERROR:", detail) 23 | return 1 24 | return 0 25 | 26 | for item in proxyList: 27 | if is_bad_proxy(item): 28 | print ("Bad Proxy", item) 29 | else: 30 | print (item, "is working") 31 | -------------------------------------------------------------------------------- /proxy_checkpy3-async.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import urllib.request, socket 3 | from threading import Thread 4 | 5 | socket.setdefaulttimeout(30) 6 | 7 | def check_proxy(pip): 8 | try: 9 | proxy_handler = urllib.request.ProxyHandler({'https': pip}) 10 | opener = urllib.request.build_opener(proxy_handler) 11 | opener.addheaders = [('User-agent', 'Mozilla/5.0')] 12 | urllib.request.install_opener(opener) 13 | sock=urllib.request.urlopen('https://www.myip.com/') # change the url address here 14 | print(pip) 15 | except urllib.error.HTTPError as e: 16 | return e 17 | except Exception as detail: 18 | return detail 19 | return 0 20 | 21 | #Example run : echo -ne "192.168.1.1:231\n192.168.1.2:231" | python proxy_checkpy3-async.py 22 | proxies = sys.stdin.readlines() 23 | threads = [] 24 | 25 | for proxy in proxies: 26 | thread = Thread( target=check_proxy, args=(proxy.strip(), )) 27 | thread.start() 28 | threads.append(thread) 29 | 30 | for thread in threads: 31 | thread.join() --------------------------------------------------------------------------------