This script fetches a URL, optionally resolves a hostname, and provides detailed information about the request and response, including headers, statistics, and an MD5 checksum of the response body. It also supports connection debugging and custom headers from a YAML file.
- Python 3.x
requestslibraryPyYAMLlibrarytabulatelibrary
Install the required libraries using pip:
pip install requests pyyaml tabulatepython ppcurl.py [options] URL [hostname]URL: The URL to fetch.hostname(optional): The hostname to resolve. This allows forcing the connection through the named proxy
--connection_debug: Enable connection debug mode.--stdout: Output the response body to stdout.--header_file: Path to the YAML file with header array.
python script.py --connection_debug --stdout --header_file headers.yaml https://example.comFormats data into a table using the tabulate library.
data: The data to be formatted.headers: Optional headers for the table.width: Maximum column width.
Resolves the IP address of a given hostname.
hostname: The hostname to resolve.
Loads headers from a YAML file.
header_file: Path to the YAML file.
Sets up logging to capture debug information.
Fetches the URL with the specified headers.
url: The URL to fetch.headers: The headers to include in the request.
Prints statistics about the HTTP request.
response: The HTTP response object.ip_address: The resolved IP address of the hostname.
- Argument Parsing: Parses command-line arguments using
argparse. - Header Loading: Loads headers from a YAML file if provided.
- Logging Setup: Sets up logging if connection debugging is enabled.
- Hostname Resolution: Resolves the hostname and optional proxy hostname.
- URL Fetching: Fetches the URL with the specified headers.
- Output: Prints the response body, request headers, response headers, and request statistics. If connection debugging is enabled, prints the connection log and MD5 checksum of the response body.
headers:
X-Unicorn-Magic: SparkleDust
X-Random-Header: 42
X-Meaningless-Value: FlibberFlabber
X-Confusion-Level: Maximum
X-Nonexistent-Feature: QuantumFlux
X-Just-For-Fun: BananaBread
X-Absurdity: Over9000- Ensure the YAML file is correctly formatted.
- The script disables SSL verification (
verify=False). Use with caution in production environments.