def fetch_proxies() -> list:
if not USE_PROXY:
return ["直连"]
try:
resp = requests.get(PROXY_API_URL, timeout=10)
if resp.status_code == 200:
proxies = resp.text.strip().splitlines()
valid_ips = [ip for ip in proxies if ":" in ip and len(ip.split(":")) == 2]
if valid_ips:
print(f"获取到 {len(valid_ips)} 个有效代理 IP")
return valid_ips
else:
print("代理内容格式异常,将使用直连。")
else:
print(f"代理请求失败,状态码:{resp.status_code},将使用直连。")
except Exception as e:
print(f"代理接口异常:{e},将使用直连。")
return ["直连"]