aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2016-06-14 16:29:15 +1200
committerGitHub <noreply@github.com>2016-06-14 16:29:15 +1200
commit93276d45be68790b5f4aeb4577c380ca1608efb3 (patch)
tree9553d0f45e705da04bfa4be8dd5e39d09fcd112f /examples
parent4c292b0197d820e9e108aa05b10927107a0503c3 (diff)
parentd8ae2f156203a81a8e6d325f5c460c351cfbfc5c (diff)
downloadmitmproxy-93276d45be68790b5f4aeb4577c380ca1608efb3.tar.gz
mitmproxy-93276d45be68790b5f4aeb4577c380ca1608efb3.tar.bz2
mitmproxy-93276d45be68790b5f4aeb4577c380ca1608efb3.zip
Merge branch 'master' into netlibrace
Diffstat (limited to 'examples')
-rw-r--r--examples/custom_contentviews.py2
-rw-r--r--examples/filt.py8
-rw-r--r--examples/flowwriter.py8
-rw-r--r--examples/har_extractor.py7
-rw-r--r--examples/iframe_injector.py7
-rw-r--r--examples/modify_response_body.py8
-rw-r--r--examples/proxapp.py2
-rw-r--r--examples/sslstrip.py2
-rw-r--r--examples/stub.py2
-rw-r--r--examples/tcp_message.py4
-rw-r--r--examples/tls_passthrough.py7
11 files changed, 31 insertions, 26 deletions
diff --git a/examples/custom_contentviews.py b/examples/custom_contentviews.py
index 034f356c..05ebeb69 100644
--- a/examples/custom_contentviews.py
+++ b/examples/custom_contentviews.py
@@ -62,7 +62,7 @@ class ViewPigLatin(contentviews.View):
pig_view = ViewPigLatin()
-def start(context, argv):
+def start(context):
context.add_contentview(pig_view)
diff --git a/examples/filt.py b/examples/filt.py
index f99b675c..1a423845 100644
--- a/examples/filt.py
+++ b/examples/filt.py
@@ -1,13 +1,13 @@
# This scripts demonstrates how to use mitmproxy's filter pattern in inline scripts.
# Usage: mitmdump -s "filt.py FILTER"
-
+import sys
from mitmproxy import filt
-def start(context, argv):
- if len(argv) != 2:
+def start(context):
+ if len(sys.argv) != 2:
raise ValueError("Usage: -s 'filt.py FILTER'")
- context.filter = filt.parse(argv[1])
+ context.filter = filt.parse(sys.argv[1])
def response(context, flow):
diff --git a/examples/flowwriter.py b/examples/flowwriter.py
index 8fb8cc60..cb5ccb0d 100644
--- a/examples/flowwriter.py
+++ b/examples/flowwriter.py
@@ -4,14 +4,14 @@ import sys
from mitmproxy.flow import FlowWriter
-def start(context, argv):
- if len(argv) != 2:
+def start(context):
+ if len(sys.argv) != 2:
raise ValueError('Usage: -s "flowriter.py filename"')
- if argv[1] == "-":
+ if sys.argv[1] == "-":
f = sys.stdout
else:
- f = open(argv[1], "wb")
+ f = open(sys.argv[1], "wb")
context.flow_writer = FlowWriter(f)
diff --git a/examples/har_extractor.py b/examples/har_extractor.py
index 6806989d..c21f1a8f 100644
--- a/examples/har_extractor.py
+++ b/examples/har_extractor.py
@@ -3,6 +3,7 @@
https://github.com/JustusW/harparser to generate a HAR log object.
"""
import six
+import sys
from harparser import HAR
from datetime import datetime
@@ -52,15 +53,15 @@ class _HARLog(HAR.log):
return self.__page_list__
-def start(context, argv):
+def start(context):
"""
On start we create a HARLog instance. You will have to adapt this to
suit your actual needs of HAR generation. As it will probably be
necessary to cluster logs by IPs or reset them from time to time.
"""
context.dump_file = None
- if len(argv) > 1:
- context.dump_file = argv[1]
+ if len(sys.argv) > 1:
+ context.dump_file = sys.argv[1]
else:
raise ValueError(
'Usage: -s "har_extractor.py filename" '
diff --git a/examples/iframe_injector.py b/examples/iframe_injector.py
index ad844f19..9495da93 100644
--- a/examples/iframe_injector.py
+++ b/examples/iframe_injector.py
@@ -1,13 +1,14 @@
# Usage: mitmdump -s "iframe_injector.py url"
# (this script works best with --anticache)
+import sys
from bs4 import BeautifulSoup
from mitmproxy.models import decoded
-def start(context, argv):
- if len(argv) != 2:
+def start(context):
+ if len(sys.argv) != 2:
raise ValueError('Usage: -s "iframe_injector.py url"')
- context.iframe_url = argv[1]
+ context.iframe_url = sys.argv[1]
def response(context, flow):
diff --git a/examples/modify_response_body.py b/examples/modify_response_body.py
index d68bcf63..3034892e 100644
--- a/examples/modify_response_body.py
+++ b/examples/modify_response_body.py
@@ -1,14 +1,16 @@
# Usage: mitmdump -s "modify_response_body.py mitmproxy bananas"
# (this script works best with --anticache)
+import sys
+
from mitmproxy.models import decoded
-def start(context, argv):
- if len(argv) != 3:
+def start(context):
+ if len(sys.argv) != 3:
raise ValueError('Usage: -s "modify_response_body.py old new"')
# You may want to use Python's argparse for more sophisticated argument
# parsing.
- context.old, context.new = argv[1], argv[2]
+ context.old, context.new = sys.argv[1], sys.argv[2]
def response(context, flow):
diff --git a/examples/proxapp.py b/examples/proxapp.py
index 4d8e7b58..613d3f8b 100644
--- a/examples/proxapp.py
+++ b/examples/proxapp.py
@@ -15,7 +15,7 @@ def hello_world():
# Register the app using the magic domain "proxapp" on port 80. Requests to
# this domain and port combination will now be routed to the WSGI app instance.
-def start(context, argv):
+def start(context):
context.app_registry.add(app, "proxapp", 80)
# SSL works too, but the magic domain needs to be resolvable from the mitmproxy machine due to mitmproxy's design.
diff --git a/examples/sslstrip.py b/examples/sslstrip.py
index 1bc89946..8dde8e3e 100644
--- a/examples/sslstrip.py
+++ b/examples/sslstrip.py
@@ -3,7 +3,7 @@ import re
from six.moves import urllib
-def start(context, argv):
+def start(context):
# set of SSL/TLS capable hosts
context.secure_hosts = set()
diff --git a/examples/stub.py b/examples/stub.py
index 516b71a5..a0f73538 100644
--- a/examples/stub.py
+++ b/examples/stub.py
@@ -3,7 +3,7 @@
"""
-def start(context, argv):
+def start(context):
"""
Called once on script startup, before any other events.
"""
diff --git a/examples/tcp_message.py b/examples/tcp_message.py
index 2c210618..78500c19 100644
--- a/examples/tcp_message.py
+++ b/examples/tcp_message.py
@@ -1,4 +1,4 @@
-'''
+"""
tcp_message Inline Script Hook API Demonstration
------------------------------------------------
@@ -7,7 +7,7 @@ tcp_message Inline Script Hook API Demonstration
example cmdline invocation:
mitmdump -T --host --tcp ".*" -q -s examples/tcp_message.py
-'''
+"""
from netlib import strutils
diff --git a/examples/tls_passthrough.py b/examples/tls_passthrough.py
index 0c6d450d..50aab65b 100644
--- a/examples/tls_passthrough.py
+++ b/examples/tls_passthrough.py
@@ -24,6 +24,7 @@ from __future__ import (absolute_import, print_function, division)
import collections
import random
+import sys
from enum import Enum
from mitmproxy.exceptions import TlsProtocolException
@@ -110,9 +111,9 @@ class TlsFeedback(TlsLayer):
# inline script hooks below.
-def start(context, argv):
- if len(argv) == 2:
- context.tls_strategy = ProbabilisticStrategy(float(argv[1]))
+def start(context):
+ if len(sys.argv) == 2:
+ context.tls_strategy = ProbabilisticStrategy(float(sys.argv[1]))
else:
context.tls_strategy = ConservativeStrategy()