Last active
August 29, 2015 14:05
-
-
Save hkurokawa/e1f4f641f7935dc50ddf to your computer and use it in GitHub Desktop.
モバイルアプリ開発者のための mitmproxy 入門 ref: http://qiita.com/hkurokawa/items/9034274cc1b9e1405c68
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install mitmproxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% mitmproxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mitmproxy -s test_mitmproxy.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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