mitmproxy/pathoc
2012-09-26 10:12:30 +12:00

88 lines
2.6 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(
"-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(
'host', type=str,
help='Host to connect to'
)
parser.add_argument(
'request', type=str, nargs="+",
help='Request specification'
)
group = parser.add_argument_group('Controlling Output')
group.add_argument(
"-e", dest="explain", action="store_true", default=False,
help="Explain requests."
)
group.add_argument(
"-q", dest="showreq", action="store_true", default=False,
help="Print full request."
)
group.add_argument(
"-r", dest="showresp", action="store_true", default=False,
help="Print full response."
)
group.add_argument(
"-x", dest="hexdump", action="store_true", default=False,
help="Output in hexdump format."
)
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,
showreq=args.showreq,
showresp=args.showresp,
explain=args.explain,
hexdump=args.hexdump,
)
sys.stdout.flush()
except KeyboardInterrupt:
pass