-
Notifications
You must be signed in to change notification settings - Fork 3
/
checker.py
35 lines (30 loc) · 1.3 KB
/
checker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Python HTTP(s) proxy checker coded by zxcr9999
import argparse
import requests
import threading
alive_proxies = []
def check_proxy(ip, port):
try:
proxy = f'http://{ip}:{port}'
response = requests.get('https://www.google.com', proxies={'http': proxy, 'https': proxy}, timeout=5)
if response.status_code == 200:
print(f'[ALIVE] {ip}:{port}')
with open('alive_proxies.txt', 'a') as f:
f.write(f'{ip}:{port}\n')
except:
print(f'[DEAD] {ip}:{port}')
parser = argparse.ArgumentParser(description='HTTP(s) Proxy checker')
parser.add_argument('proxy_file', help='Proxy file for checking')
parser.add_argument('--threads', type=int, default=10, help='Number threads using for checking proxy')
args = parser.parse_args()
with open(args.proxy_file, 'r') as f:
proxies = [line.strip().split(':') for line in f]
num_threads = args.threads
proxy_parts = [proxies[i:i + len(proxies) // num_threads] for i in range(0, len(proxies), len(proxies) // num_threads)]
threads = []
for i in range(num_threads):
thread = threading.Thread(target=lambda proxies: [check_proxy(ip, port) for ip, port in proxies], args=(proxy_parts[i],))
threads.append(thread)
thread.start()
for thread in threads:
thread.join()