Mitmproxy 最新新版配置上游代理
由于在 4.0版本之后flow.live.change_upstream_proxy_server(proxy)方法已经弃用,
会引发:
AttributeError: 'NoneType' object has no attribute 'change_upstream_proxy_server'
使用flow.server_conn.via = ServerSpec(("http", proxy))方法配置上游代理
#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@file:maplocal.py
@time:2022/11/27
"""
from mitmproxy import http
import requests
from mitmproxy import ctx
from mitmproxy.net.server_spec import ServerSpec
class MitmProxy:
def __init__(self):
self.name = 'mitmproxy'
def request(self, flow: http.HTTPFlow):
# if the decision is done by domain, one could alse modify the server address here.
# We do it after CONNECT here to have the reqeust data available as well.
client_ip = flow.client_conn.address[0]
if 'get' in flow.request.url:
ip_ = '上游代理ip:str'
port_ = '上游代理端口:int'
proxy = (ip_, int(port_))
flow.server_conn.via = ServerSpec(("http", proxy))
addons = [
MitmProxy()
]
然后直接使用在命令行运行Mitmproxy
mitmdump -s 绝对路径/mitmdump.py -p 端口