To make Python's requests library use the IPv4 address of a target server via a SOCKS proxy created with ssh -D, you need to:
Set up the SOCKS proxy using ssh -D.
Configure requests to route traffic through that SOCKS proxy.
Ensure the SOCKS proxy resolves hostnames to IPv4 (not IPv6) if needed.
đ§ Step 1: Create the SOCKS Proxy with ssh -D
On your local machine, run:
bash
ssh -D 1080 user@target-server
-D 1080: Creates a SOCKS proxy on port 1080 on your local machine.
user@target-server: The SSH user and target server (Debian 13) you want to route traffic through.
â ď¸ This SOCKS proxy runs on your local machine, not the target server. The traffic will be tunneled through the SSH connection to the target server.
đ Step 2: Use the SOCKS Proxy in Python requests
The requests library does not natively support SOCKS. You need to use the requests[socks] package.