import requests
def check_proxy(proxy):
try:
response = requests.get('http://example.com', proxies={'http': proxy, 'https': proxy}, timeout=10)
if response.status_code == 200:
print(f"Proxy {proxy} is working!")
else:
print(f"Proxy {proxy} is not working. Status code: {response.status_code}")
except Exception as e:
print(f"Proxy {proxy} is not working. Exception: {e}")
# Replace 'http://example.com' with the URL you want to use for testing
# Replace 'proxy_ip:port' with the actual proxy IP and port
proxy_to_check = 'proxy_ip:port'
check_proxy(proxy_to_check)
Đảm bảo thay thế 'proxy_ip:port'
với IP proxy và cổng thực tế mà bạn muốn kiểm tra. Kịch bản này gửi yêu cầu tới http://example.com
sử dụng proxy được cung cấp và kiểm tra xem mã trạng thái phản hồi có phải là 200 hay không. Nếu mã trạng thái là 200, nó sẽ in ra rằng proxy đang hoạt động; nếu không, nó sẽ in một thông báo lỗi. Điều chỉnh URL và giá trị thời gian chờ nếu cần.
Bình luận (0)
Chưa có bình luận nào ở đây, bạn có thể là người đầu tiên!