Proxy Checker (Python script) 03-18-2016, 01:01 AM
#1
I was bored, so I made this Python script that reads a list of proxies from a file and then writes all the still-working proxies to an out file.
Example usage:
If you liked or found this useful, please comment.
Code:
from Queue import Queue
from threading import Thread
import argparse
import requests
import sys
import time
def process_proxy():
try:
while True:
proxy = queue.get()
if proxy == "STOP":
return
save_valid_proxy(check_proxy(proxy))
queue.task_done()
except:
pass
def check_proxy(proxy, timeout = 5, url = "https://google.com"):
proxies = {
"http": "http://" + proxy,
"https": "https://" + proxy
}
try:
r = requests.get(url, proxies = proxies, timeout = timeout)
except IOError:
return False
return proxy
def save_valid_proxy(proxy):
if proxy:
OUT_F.write(proxy + "\n")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description = "Check a proxy list for working proxies.")
parser.add_argument("infile", help = "The proxy list file.")
parser.add_argument("outfile", help = "The output file.")
parser.add_argument("-t", "--threads", type = int, help = "Set the number of threads running concurrently.")
parser.add_argument("-v", "--verbose", action = "store_true", help = "Be verbose?")
args = parser.parse_args()
IN_F = open(args.infile, "r")
OUT_F = open(args.outfile, "w")
# number of threads running at once
if args.threads:
concurrent_threads = args.threads
else:
concurrent_threads = 250
if args.verbose:
print("Loading proxy list from: {}".format(args.infile))
print("Saving valid proxies list to: {}".format(args.outfile))
print("Running: {} threads...".format(concurrent_threads))
queue = Queue(concurrent_threads * 2)
for i in range(0, concurrent_threads):
thread = Thread(target = process_proxy)
thread.setDaemon(True)
thread.start()
start = time.time()
try:
for proxy in IN_F:
queue.put(proxy.strip())
# queue.join()
except KeyboardInterrupt:
pass
print("Closing down, please wait. ({} seconds run time)".format(time.time() - start))
queue.put("STOP")
IN_F.close()
OUT_F.close()
sys.exit()Example usage:
Code:
proxy_checker.py proxylist.txt validproxies.txt --threads 500If you liked or found this useful, please comment.





![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)