### [代理IP搭配自动化脚本 用Python写一个定时切换IP的脚本](https://www.jiyueip.com/article/12986) **Published:** 2026-07-29T01:52:56 **Author:** 斑斓 **Excerpt:** 手写一个Python自动化脚本,定时从代理平台API提取新IP、替换配置文件里的旧IP、重启代理客户端。完整的… 代理IP用久了需要换,手动太麻烦。用Python写个自动化脚本。 import requests, time, subprocess API\_URL = "https://平台API/提取IP" CONFIG\_FILE = "proxy\_config.txt" def get\_new\_ip(): resp = requests.get(API\_URL).json() return resp\['ip'\], resp\['port'\] def update\_config(ip, port): with open(CONFIG\_FILE, 'w') as f: f.write(f"{ip}:{port}") def restart\_proxy(): subprocess.run(\["taskkill", "/F", "/IM", "proxifier.exe"\]) time.sleep(3) subprocess.Popen(\["proxifier.exe"\]) while True: ip, port = get\_new\_ip() update\_config(ip, port) restart\_proxy() time.sleep(3600 \* 6) # 每6小时换一次 天行IP邀请码blsj月付6元多节点配合API自动化脚本。 **免责声明**:代码仅供学习。 **Tags:** 代理IP, 网站运维 **Categories:** 行业洞察 ---