Skip to content
Command-line arguments

Command-line arguments

CLI args — argparse (full template + conditional proxy)

argparse.ArgumentParser defines the accepted command-line options, converts their text values into the selected Python types, and stores the parsed results in args. The target is required. The proxy is optional and produces an empty PROXIES dictionary when omitted, which allows the same request calls to run with or without Burp.

import requests
import urllib3
import argparse
import sys
from colorama import Fore, init

init(autoreset=True)
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

parser = argparse.ArgumentParser(
    description="Description of what this exploit does.",
    epilog=f"Example: {sys.argv[0]} -t http://example.com [-x http://127.0.0.1:8080]")
parser.add_argument("-t", "--target", required=True, type=str, help="URL of the target, including the port.")
parser.add_argument("-x", "--proxy", required=False, type=str, help="Optional proxy to pass traffic through.", default=None)
args = parser.parse_args()

PROXY = args.proxy
if PROXY is not None:
    PROXY = PROXY.strip()
    PROXIES = {
        "http": PROXY,
        "https": PROXY
    }
else:
    PROXIES = {}
URL = args.target.rstrip("/").strip()

if __name__ == "__main__":
    s = requests.Session()

Find by: command line, arguments, args, flags, parameters, options, argparse, cli, target, proxy, boilerplate, starter, template, colorama, colored output · Source: CWEE/many