我正在使用mitmproxy和python作为http代理
我使用以下命令运行代理:
mitmdump -s proxy.py -U http://upstreamproxy
proxy.py如下:
#!/usr/bin/mitmdump
from __future__ import print_function
import pprint
import datetime
import os
import re
pp = pprint.PrettyPrinter(indent=4)
def request(context, flow):
print("DEBUG")
oldhost = flow.request.host
flow.request.url = re.sub(r"www.verycd.com",r"115.182.66.26",flow.request.url)
# flow.request.host = oldhost #<---This will modify the url also
print("DEBUG")
我希望将www.verycd.com更改为网址中的IP,但保持主机字段仍然使用www.verycd.com,如下所示:
GET http://115.182.66.26/ HTTP/1.1
TE: deflate,gzip;q=0.3
Connection: TE, close
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: zh,en-US;q=0.5
Host: www.verycd.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0
但是,mitmproxy总是同时改变网址和主机 我得到了服务器不接受的跟随
GET http://115.182.66.26/ HTTP/1.1
TE: deflate,gzip;q=0.3
Connection: TE, close
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: zh,en-US;q=0.5
Host: 115.182.66.26
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0