mitmproxy/pathoc

64 lines
1.8 KiB
Plaintext
Raw Normal View History

#!/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()
2012-06-24 09:40:31 +00:00
if args.port is None:
port = 443 if args.ssl else 80
else:
port = args.port
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:
p.convert_to_ssl(sni=args.sni)
if args.timeout:
p.settimeout(args.timeout)
p.print_requests(args.request, args.verbose, args.reqdump)