Pyton HTTP/S4/S5 Proxy Checker

Written Pyton HTTP/S/S Proxy Checker by proxy checker hide my name a friend named Bobng for me to validate a list of proxies. Hope you guys enjoy.

Command line running: python script.py LIST.txt TYPE OUTPUT.txt
Replace LIST with the list of proxies in a proxy checker github text file, in the format:

IPORT
IPORT
IPORT
Click to expand…

Replace TYPE with the type of proxy. If HTTP, then “http”. If socks4, “socks4”, if socks5, “socks5”.
Replace OUTPUT with the file you want the working proxies to be sent out to.

Once it’s done, it will say Finished, and you can end it with the Enter key.

Code:
import socks
import urllib2
import threading
import sys
import Queue
import socket
socket.setdefaulttimeout(5)
print "Bobng's proxy checker. Using %s second timeout"%(socket.getdefaulttimeout())

input_file = sys.argv[1]
proxy_type = sys.argv[2] #options: http,s4,s5
output_file = sys.argv[3]

url = "www.seemyip.com" # Don't put http:// in here, or any /'s

check_queue = Queue.Queue()
output_queue = Queue.Queue()
threads = 60

def writer(f,rq):
    while True:
        line = rq.get()
        f.write(line+'\n')

def checker(q,oq):
    while True:
        proxy_info = q.get() #ip:port
        if proxy_info == None:
            print "Finished"
            return
        #print "Checking %s"%proxy_info
        if proxy_type == "http":
            try:
                proxy_handler  python http request = urllib2.ProxyHandler({'http':proxy_info})
                opener = urllib2.build_opener(proxy_handler)
                opener.addheaders = [('User-agent','Mozilla/5.0')]
                urllib2.install_opener(opener)
                req = urllib2.Request("http://"+url+'/')
                sock=urllib2.urlopen(req)
                oq.put(proxy_info)
                print proxy_info
            except urllib2.HTTPError,e:
                pass
            except Exception,detail:
                print proxy_info
                
        else:
            # gotta be socks
            try:
                s = socks.socksocket()
                if proxy_type == "s4":
                    t = socks.PROXY_TYPE_SOCKS4
                else:
                    t = socks.PROXY_TYPE_SOCKS5
                ip,port = proxy_info.split(':')
                s.setproxy(t,ip,int(port))
                s.connect((url,80))
                oq.put(proxy_info)
                print proxy_info
            except Exception,error:
                print proxy_info
                
threading.Thread(target=writer,args=(open(output_file,"wb"),output_queue)).start()
for i in xrange(threads):
    threading.Thread(target=checker,args=(check_queue,output_queue)).start()
for line in open(input_file).readlines():
    check_queue.put(line.strip('\n'))
print "File reading done"
for i in xrange(threads):
    check_queue.put(None)
raw_input("PRESS ENTER  proxy checker download TO QUIT")
sys.exit(0)

Enjoy, rep/comment if you like! :)

 

jbrothersgroup

Leave a Reply

Your email address will not be published. Required fields are marked *