-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathprox_check.py
More file actions
executable file
·45 lines (38 loc) · 1.42 KB
/
prox_check.py
File metadata and controls
executable file
·45 lines (38 loc) · 1.42 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
#!/usr/bin/env python3
"""Proxy server checker for ProxyHunter."""
import requests
def is_prox(proxy_server):
"""
Check if the given proxy server works for HTTP, HTTPS, or SOCKS5.
Args:
proxy_server (str): Proxy address, e.g. 'http://1.2.3.4:8080' or 'socks5://1.2.3.4:1080'
Returns:
str: The proxy type that works ('http', 'https', 'socks5'), or None if none work.
"""
proxy_types = {
"http": proxy_server,
"https": proxy_server,
"socks5": proxy_server # requests supports 'socks5' with 'requests[socks]'
}
test_site = "http://api.ipify.org/?format=json"
headers = {
'User-Agent': ('Mozilla/5.0 (Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/'
'20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)')
}
for proxy_type, proxy_addr in proxy_types.items():
proxies = {proxy_type: proxy_addr}
try:
r = requests.get(test_site, headers=headers, proxies=proxies, timeout=3)
if r.status_code == 200:
return proxy_type
except requests.RequestException:
continue
return None
if __name__ == '__main__':
# Example usage; replace with actual address or CLI argument
test_proxy = "http://1.2.3.4:8080"
working_type = is_prox(test_proxy)
if working_type:
print(f"Proxy works for: {working_type}")
else:
print("No working proxy type found.")