mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 16:17:49 +00:00
73 lines
2.1 KiB
Python
Executable File
73 lines
2.1 KiB
Python
Executable File
#!/usr/bin/env python
|
|
import argparse, sys
|
|
from libpathod import pathoc, version, rparse
|
|
from netlib import tcp
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description='A perverse HTTP client.')
|
|
parser.add_argument(
|
|
"-i", dest="sni", type=str, default=False,
|
|
help="SSL Server Name Indication."
|
|
)
|
|
parser.add_argument(
|
|
"-n", dest='repeat', default=1, type=int, metavar="N",
|
|
help='Repeat requests N times.'
|
|
)
|
|
parser.add_argument(
|
|
"-p", dest="port", type=int, default=None,
|
|
help="Port. Defaults to 80, or 443 if SSL is active."
|
|
)
|
|
parser.add_argument(
|
|
"-d", dest="reqdump", action="store_true", default=False,
|
|
help="Print request record before each response."
|
|
)
|
|
parser.add_argument(
|
|
"-s", dest="ssl", action="store_true", default=False,
|
|
help="Connect with SSL."
|
|
)
|
|
parser.add_argument(
|
|
"-t", dest="timeout", type=int, default=None,
|
|
help="Connection timeout."
|
|
)
|
|
parser.add_argument(
|
|
"-v", dest="verbose", action='count',
|
|
help="Increase verbosity."
|
|
)
|
|
parser.add_argument(
|
|
'host', type=str,
|
|
help='Host to connect to'
|
|
)
|
|
parser.add_argument(
|
|
'request', type=str, nargs="+",
|
|
help='Request specification'
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
if args.port is None:
|
|
port = 443 if args.ssl else 80
|
|
else:
|
|
port = args.port
|
|
|
|
try:
|
|
for i in range(args.repeat):
|
|
p = pathoc.Pathoc(args.host, port)
|
|
try:
|
|
p.connect()
|
|
except tcp.NetLibError, v:
|
|
print >> sys.stderr, str(v)
|
|
sys.exit(1)
|
|
if args.ssl:
|
|
try:
|
|
p.convert_to_ssl(sni=args.sni)
|
|
except tcp.NetLibError, v:
|
|
print "\n>> %s"%v
|
|
continue
|
|
if args.timeout:
|
|
p.settimeout(args.timeout)
|
|
p.print_requests(args.request, args.verbose, args.reqdump)
|
|
sys.stdout.flush()
|
|
except KeyboardInterrupt:
|
|
pass
|
|
|