42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
import requests
|
|
|
|
def read_proxies(file_path):
|
|
with open(file_path, "r") as file:
|
|
proxies_list = file.read().strip().split("\n")
|
|
return proxies_list
|
|
|
|
def get(url, proxy):
|
|
try:
|
|
# Parse the proxy string
|
|
proxy_type, ip, port = proxy.split()
|
|
proxy_url = f"{proxy_type.lower()}://{ip}:{port}"
|
|
|
|
# Send proxy requests to the final URL
|
|
response = requests.get(url, proxies={'http': proxy_url, 'https': proxy_url}, timeout=5)
|
|
if response.status_code == 200:
|
|
response_lines = response.text.strip().split("\n")
|
|
ip_info = {}
|
|
for line in response_lines:
|
|
key, value = line.split(": ", 1)
|
|
ip_info[key] = value
|
|
|
|
if ip_info.get('IP地址') == ip_info.get('X-Forwarded-For') == ip_info.get('X-Real-IP') == ip:
|
|
print(f"Proxy: {proxy} is available.")
|
|
else:
|
|
print(f"Proxy: {proxy} is not available.")
|
|
print(f"IP地址: {ip_info.get('IP地址')}")
|
|
print(f"X-Forwarded-For: {ip_info.get('X-Forwarded-For')}")
|
|
print(f"X-Real-IP: {ip_info.get('X-Real-IP')}")
|
|
else:
|
|
print(f"Failed to connect with proxy {proxy}. Status code: {response.status_code}")
|
|
except Exception as e:
|
|
print(f"Error with proxy {proxy}: {e}")
|
|
|
|
def check_proxies(proxies_list, test_url):
|
|
for proxy in proxies_list:
|
|
get(test_url, proxy)
|
|
|
|
if __name__ == "__main__":
|
|
proxies = read_proxies("proxies_list.txt")
|
|
test_url = "https://test.masonliu.com/api/IP-test.php"
|
|
check_proxies(proxies, test_url) |