def test_ip():
test_url = "https://www.baidu.com"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'
}
while True:
temp_ip, temp_port = getIp()
print(f"开始测试 {temp_ip}:{temp_port}")
proxies = {
"http": f"http://{temp_ip}:{temp_port}/",
"https": f"http://{temp_ip}:{temp_port}/"
}
try:
result = requests.get(url=test_url, headers=headers, proxies=proxies, timeout=3)
if result.status_code == 200:
print(f"{temp_ip}:{temp_port},可通baidu")
print(result.text)
return temp_ip, temp_port
else:
print(f"{temp_ip}:{temp_port},不通baidu")
continue
except Exception as exception:
print(exception)
continue