Skip to content

Log HTTP/S traffic #6844

Answered by emanuele-em
chrisfrederik asked this question in Q&A
May 11, 2024 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

Hi! I think that you can use mitmproxy addons, I write a working but simple script for you that should do what you need:

from mitmproxy import ctx

class TrafficLogger:
    def __init__(self):
        self.log_file = open("traffic_log.txt", "a")

    def response(self, flow):
        self.log_file.write("=============================\n")
        self.log_file.write(f"Request: {flow.request.method} {flow.request.url}\n")
        self.log_file.write(f"Response: {flow.response.status_code}\n")
        self.log_file.write("=============================\n\n")
        self.log_file.flush()

    def done(self):
        self.log_file.close()

addons = [
    TrafficLogger()
]

save it as traffic_l…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by chrisfrederik
Comment options

You must be logged in to vote
1 reply
@rosydawn6
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants