Exit mitmdump from a python script

1.4k views Asked by At

How can I exit mitmpdump command from a script?

Tried sys.exit(0) but it doesn't finish the process mitmpdump, it only stops filtering.

This is my script

"""
This script adds a filter.
Usage:
  mitmdump -s "script.py"
"""
import sys
from mitmproxy import flowfilter

class Filter:
  def __init__(self):
    self.filter = flowfilter.parse("~h my_filter")

  def response(self, flow):
    if flowfilter.match(self.filter, flow):
      print("Flow matches filter:")
      print(flow.request.headers["my_filter"])
      sys.exit(0)

def start():
  return Filter()
1

There are 1 answers

0
User9123 On BEST ANSWER

The following is working for me on v9.0.1

from mitmproxy import ctx
ctx.master.shutdown() #place this in the code where you want to trigger the shutdown