-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxytest.py
More file actions
101 lines (82 loc) · 2.59 KB
/
proxytest.py
File metadata and controls
101 lines (82 loc) · 2.59 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import requests
import time
import argparse
from concurrent.futures import ThreadPoolExecutor, as_completed
# ===== DEFAULT CONFIG =====
PROXY_FILE = "proxies.txt"
TIMEOUT = 5
THREADS = 30
TEST_URL = "http://httpbin.org/ip"
# =========================
def test_proxy(proxy):
proxies = {
"http": proxy,
"https": proxy
}
start = time.time()
try:
r = requests.get(TEST_URL, proxies=proxies, timeout=TIMEOUT)
latency = int((time.time() - start) * 1000)
if r.status_code == 200:
print(f"[ OK ] {proxy:<35} {latency} ms")
return proxy
else:
print(f"[BAD] {proxy:<35} HTTP {r.status_code}")
return None
except Exception:
print(f"[DEAD] {proxy}")
return None
def to_proxychains(proxy):
"""
Convert:
socks5://1.2.3.4:1080
→ socks5 1.2.3.4 1080
"""
proto, rest = proxy.split("://")
ip, port = rest.split(":")
return f"{proto} {ip} {port}"
def main():
parser = argparse.ArgumentParser(description="Fast proxy tester & cleaner")
parser.add_argument(
"--proxychains",
action="store_true",
help="Write output in proxychains format"
)
parser.add_argument(
"-f", "--file",
default=PROXY_FILE,
help="Proxy file (default: proxies.txt)"
)
args = parser.parse_args()
proxy_file = args.file
with open(proxy_file, "r") as f:
proxies = [
line.strip()
for line in f
if line.strip() and not line.startswith("#")
]
print(f"\n[*] Testing {len(proxies)} proxies...\n")
working = []
with ThreadPoolExecutor(max_workers=THREADS) as executor:
futures = {executor.submit(test_proxy, p): p for p in proxies}
for future in as_completed(futures):
result = future.result()
if result:
working.append(result)
# Write output
with open(proxy_file, "w") as f:
if args.proxychains:
f.write("# ProxyChains format\n")
f.write("[ProxyList]\n")
for proxy in working:
f.write(to_proxychains(proxy) + "\n")
else:
for proxy in working:
f.write(proxy + "\n")
print("\n==============================")
print(f"[✓] Working proxies saved : {len(working)}")
print(f"[✗] Removed dead proxies : {len(proxies) - len(working)}")
print(f"[i] Output format : {'proxychains' if args.proxychains else 'original'}")
print("==============================\n")
if __name__ == "__main__":
main()