aio老陈已验证有效, 原文链接
配置使用mitmproxy版本信息如下
Mitmproxy: 4.0.4
Python: 3.6.3
配置步骤实际相当简单,但所有步骤缺一不可:
第一步 命令行启用upstream模式
注:只有在一开始启动了upstream模式,后续才可以进行定制化跳转
mitmdump --mode upstream:http://default-upstream-proxy.local:8080/ -s ./change_upstream_proxy.py
第二步 mitmdump脚本根据所需定义规则跳转不同的二级代理
def request(flow: http.HTTPFlow) -> None:
if flow.request.method == "CONNECT":
# If the decision is done by domain, one could also modify the server address here.
# We do it after CONNECT here to have the request data available as well.
return
client_ip = flow.client_conn.address[0]
if 'ip.cn' in flow.request.url:
ctx.log.info(flow.request.url)
proxy =("localhost", 8888)
else:
proxy = ("localhost", 3800)
# 这里配置二级代理的ip地址和端口
if flow.live:
flow.live.change_upstream_proxy_server(proxy)
第三步 测试结果
设备连接mitmproxy后,访问www.ip.cn 及 httpbin.org/ip