From 11fd49de62196e1cb4c1ba2115c4de428ae6a9e4 Mon Sep 17 00:00:00 2001 From: imDMG Date: Thu, 7 May 2020 21:56:58 +0500 Subject: [PATCH] added proxychecker.py --- .gitignore | 1 + proxychecker.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 proxychecker.py diff --git a/.gitignore b/.gitignore index fb93ec0..ff436be 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ /rutracker.json.bak /rutor.ico /rutor.json +/proxylist.txt diff --git a/proxychecker.py b/proxychecker.py new file mode 100644 index 0000000..1f2e056 --- /dev/null +++ b/proxychecker.py @@ -0,0 +1,32 @@ +from concurrent.futures.thread import ThreadPoolExecutor +from urllib.request import build_opener, ProxyHandler + +HOST = "http://kinozal.tv/" +SCHEME = HOST[:4] +PROXY_FILE = "proxylist.txt" # one address per line + + +def print_good_proxy(proxy): + try: + opener = build_opener(ProxyHandler({f"{SCHEME}": proxy})) + opener.addheaders = [("User-agent", "Mozilla/5.0")] + req = opener.open(HOST, timeout=30) + if not req.geturl().startswith(HOST): + raise Exception() + except Exception as e: + return e + + print(f"{proxy}") + + +def main(): + with open(PROXY_FILE) as f: + proxy_list = [x.rstrip() for x in f] + + print("Working proxies:") + with ThreadPoolExecutor(len(proxy_list)) as executor: + executor.map(print_good_proxy, proxy_list, timeout=30) + + +if __name__ == '__main__': + main()