Proxys mit cURL verwenden
cURL ist ein leistungsstarkes Befehlszeilen-Dienstprogramm für HTTP. Es unterstützt hervorragend alle Proxy-Typen.
Grundlegende Syntax
curl -x [protocol://]host:port URL
HTTP-Proxy
# Einfache Anfrage über Proxy
curl -x http://proxy.example.com:8080 https://httpbin.org/ip
# Mit Authentifizierung
curl -x http://user:password@proxy.example.com:8080 https://httpbin.org/ip
# Oder separat
curl -x http://proxy.example.com:8080 -U user:password https://httpbin.org/ip
HTTPS-Proxy
curl -x https://proxy.example.com:8080 https://httpbin.org/ip
SOCKS-Proxy
# SOCKS4
curl --socks4 proxy.example.com:1080 https://httpbin.org/ip
# SOCKS4A (DNS über Proxy)
curl --socks4a proxy.example.com:1080 https://httpbin.org/ip
# SOCKS5
curl --socks5 proxy.example.com:1080 https://httpbin.org/ip
# SOCKS5 mit DNS über Proxy (empfohlen)
curl --socks5-hostname proxy.example.com:1080 https://httpbin.org/ip
Umgebungsvariablen
# Proxy global setzen
export http_proxy=http://proxy.example.com:8080
export https_proxy=http://proxy.example.com:8080
# Jetzt gehen alle Anfragen über den Proxy
curl https://httpbin.org/ip
# Proxy für bestimmte Hosts ignorieren
export no_proxy=localhost,127.0.0.1,.internal.com
Nützliche Optionen
# Verbindungszeit anzeigen
curl -x http://proxy:8080 -w "Time: %{time_total}s\n" https://httpbin.org/ip
# SSL-Fehler ignorieren
curl -x http://proxy:8080 -k https://example.com
# Timeout setzen
curl -x http://proxy:8080 --connect-timeout 10 https://httpbin.org/ip
# Weiterleitungen folgen
curl -x http://proxy:8080 -L https://httpbin.org/redirect/3
# Cookies speichern
curl -x http://proxy:8080 -c cookies.txt https://example.com
# POST-Anfrage senden
curl -x http://proxy:8080 -X POST -d "data=value" https://httpbin.org/post
Skript zur Proxy-Listenprüfung
#!/bin/bash
while read proxy; do
result=$(curl -x "$proxy" -s --connect-timeout 5 https://httpbin.org/ip)
if [ $? -eq 0 ]; then
echo "[OK] $proxy"
else
echo "[FAIL] $proxy"
fi
done < proxies.txt
Debugging
# Ausführliche Ausgabe
curl -x http://proxy:8080 -v https://httpbin.org/ip
# Nur Header anzeigen
curl -x http://proxy:8080 -I https://httpbin.org/ip