import requests
import random

with open("proxy.txt") as f:
    lines = [l.strip() for l in f if l.strip() and not l.startswith("#")]

entry = random.choice(lines)
proxy_url = entry.split(" ")[0]

proxies = {"http": proxy_url, "https": proxy_url}

try:
    resp = requests.get("https://httpbin.org/ip", proxies=proxies, timeout=5)
    print(resp.json())
except Exception as e:
    print(f"接続失敗: {e}")