55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
import requests
|
|
from damai_proxy_config import get_proxy_config
|
|
|
|
def test_single_proxy(index):
|
|
"""测试单个代理"""
|
|
try:
|
|
# 获取代理配置
|
|
proxy_info = get_proxy_config(index)
|
|
proxy_server = proxy_info['server'].replace('http://', '')
|
|
proxy_url = f"http://{proxy_info['username']}:{proxy_info['password']}@{proxy_server}"
|
|
|
|
proxies = {
|
|
'http': proxy_url,
|
|
'https': proxy_url
|
|
}
|
|
|
|
print(f'🔍 测试代理 {index + 1}: {proxy_info["server"]}')
|
|
|
|
# 测试连接
|
|
response = requests.get('http://httpbin.org/ip', proxies=proxies, timeout=10)
|
|
|
|
if response.status_code == 200:
|
|
print(f'✅ 代理 {index + 1} 连接成功! 状态码: {response.status_code}')
|
|
print(f'🌐 IP信息: {response.text}')
|
|
return True
|
|
else:
|
|
print(f'❌ 代理 {index + 1} 连接失败! 状态码: {response.status_code}')
|
|
return False
|
|
|
|
except requests.exceptions.ProxyError:
|
|
print(f'❌ 代理 {index + 1} 连接错误:无法连接到代理服务器')
|
|
return False
|
|
except requests.exceptions.ConnectTimeout:
|
|
print(f'❌ 代理 {index + 1} 连接超时')
|
|
return False
|
|
except Exception as e:
|
|
print(f'❌ 代理 {index + 1} 连接失败: {str(e)}')
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
print("🚀 开始测试固定代理IP连接性\n")
|
|
|
|
# 测试两个代理
|
|
for i in range(2):
|
|
success = test_single_proxy(i)
|
|
if success:
|
|
print(f"✅ 代理 {i+1} 可用,适用于小红书登录发文\n")
|
|
else:
|
|
print(f"❌ 代理 {i+1} 不可用\n")
|
|
|
|
if i == 0: # 在测试第二个之前稍等一下
|
|
import time
|
|
time.sleep(2)
|
|
|
|
print("测试完成!") |