#!/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('--port', "-p", type=int, default=None, help="Port. Defaults to 80, or 443 if SSL is active.") parser.add_argument('--ssl', "-s", action="store_true", default=False, help="Connect with SSL.") parser.add_argument('--sni', "-n", type=str, default=False, help="SSL Server Name Indication.") parser.add_argument('--verbose', '-v', action='count') 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 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) p.print_requests(args.request, args.verbose)