MCPcopy Create free account
hub / github.com/mitmproxy/mitmproxy / main

Method main

examples/contrib/mitmproxywrapper.py:127–181  ·  view source on GitHub ↗
(cls)

Source from the content-addressed store, hash-verified

125
126 @classmethod
127 def main(cls):
128 parser = argparse.ArgumentParser(
129 description="Helper tool for OS X proxy configuration and mitmproxy.",
130 epilog="Any additional arguments will be passed on unchanged to mitmproxy/mitmweb.",
131 )
132 parser.add_argument(
133 "-t",
134 "--toggle",
135 action="store_true",
136 help="just toggle the proxy configuration",
137 )
138 # parser.add_argument('--honeyproxy', action='store_true', help='run honeyproxy instead of mitmproxy')
139 parser.add_argument(
140 "-p",
141 "--port",
142 type=int,
143 help="override the default port of 8080",
144 default=8080,
145 )
146 parser.add_argument(
147 "-P",
148 "--port-random",
149 action="store_true",
150 help="choose a random unused port",
151 )
152 parser.add_argument(
153 "-w",
154 "--web",
155 action="store_true",
156 help="web interface: run mitmweb instead of mitmproxy",
157 )
158 args, extra_arguments = parser.parse_known_args()
159 port = args.port
160
161 # Allocate a random unused port, and hope no other process steals it before mitmproxy/mitmweb uses it.
162 # Passing the allocated socket to mitmproxy/mitmweb would be nicer of course.
163 if args.port_random:
164 with socketserver.TCPServer(("localhost", 0), None) as s:
165 port = s.server_address[1]
166 print(f"Using random port {port}...")
167
168 wrapper = cls(port=port, use_mitmweb=args.web, extra_arguments=extra_arguments)
169
170 def handler(signum, frame):
171 print("Cleaning up proxy settings...")
172 wrapper.toggle_proxy()
173
174 signal.signal(signal.SIGINT, handler)
175
176 if args.toggle:
177 wrapper.toggle_proxy()
178 # elif args.honeyproxy:
179 # wrapper.wrap_honeyproxy()
180 else:
181 wrapper.wrap_mitmproxy()
182
183
184if __name__ == "__main__":

Callers 2

requestFunction · 0.45

Calls 2

toggle_proxyMethod · 0.80
wrap_mitmproxyMethod · 0.80

Tested by

no test coverage detected