Skip to content

Instantly share code, notes, and snippets.

@hkurokawa
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkurokawa/e1f4f641f7935dc50ddf to your computer and use it in GitHub Desktop.
Save hkurokawa/e1f4f641f7935dc50ddf to your computer and use it in GitHub Desktop.
モバイルアプリ開発者のための mitmproxy 入門 ref: http://qiita.com/hkurokawa/items/9034274cc1b9e1405c68
pip install mitmproxy
% mitmproxy
# -*- coding: utf-8 -*-
def response(context, flow):
path = flow.request.path
query = flow.request.get_query()
if path.endswith("/api/v1/list.json") and query.in_any('type', 'reload'):
flow.response.replace("艦これ", "hogehoge")
mitmproxy -s test_mitmproxy.py
# -*- coding: utf-8 -*-
import random
def start(ctx, argv):
if len(argv) != 3:
raise ValueError('Usage: -s "pseudo_unstable_network.py hostname percentage(0-10)"')
# You may want to use Python's argparse for more sophisticated argument parsing.
ctx.arg1, ctx.arg2 = argv[1], argv[2]
def request(context, flow):
host = flow.request.host
if host.endswith(context.arg1) and random.randint(0, 10) <= int(context.arg2):
context.log("Kill the request for %s. Host: %s" % (flow.request.get_url(), host))
flow.kill(context._master)
mitmproxy -s "pseudo_unstable_network.py api.example.com 8"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment