-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexamples.py
More file actions
68 lines (52 loc) · 1.95 KB
/
examples.py
File metadata and controls
68 lines (52 loc) · 1.95 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
#!/usr/bin/env python3
import os
import requests
from proxy_relay import create_proxy
PROXY_ADDR = os.getenv("UPSTREAM_PROXY", "user:pass@proxy.example.com:1080")
# TEST_URL = "http://208.95.112.1/json/"
TEST_URL = "https://api.ipify.org/"
TIMEOUT = 30
def get_direct_ip():
try:
return requests.get(TEST_URL, timeout=TIMEOUT).text.strip()
except Exception:
return None
def test_proxy(local_url):
try:
proxies = {'http': local_url, 'https': local_url}
return requests.get(TEST_URL, proxies=proxies, timeout=TIMEOUT).text.strip()
except Exception:
return None
def main():
combinations = [
("http", "http", "HTTP->HTTP"),
("http", "socks5", "HTTP->SOCKS5"),
("https", "http", "HTTPS->HTTP"),
("https", "socks5", "HTTPS->SOCKS5"),
("socks5", "http", "SOCKS5->HTTP"),
("socks5", "socks5", "SOCKS5->SOCKS5"),
("socks5h", "http", "SOCKS5H->HTTP"),
("socks5h", "socks5", "SOCKS5H->SOCKS5"),
]
direct_ip = get_direct_ip()
print(f"Direct IP: {direct_ip}\n")
results = []
for i, (upstream_proto, local_proto, desc) in enumerate(combinations, 1):
upstream_url = f"{upstream_proto}://{PROXY_ADDR}"
try:
local_url = create_proxy(upstream_url, local_proto)
proxy_ip = test_proxy(local_url)
if proxy_ip:
status = "OK" if proxy_ip != direct_ip else "WARN"
print(f"[{i}/8] {desc:20} {status:4} {proxy_ip}")
results.append((desc, True, proxy_ip))
else:
print(f"[{i}/8] {desc:20} FAIL")
results.append((desc, False, None))
except Exception as e:
print(f"[{i}/8] {desc:20} ERR {str(e)[:40]}")
results.append((desc, False, None))
success = sum(1 for _, ok, _ in results if ok)
print(f"\nSuccess rate: {success}/{len(combinations)}")
if __name__ == "__main__":
main()