Uso de Proxies con cURL
cURL es una potente utilidad de línea de comandos para HTTP. Soporta excelentemente todos los tipos de proxy.
Sintaxis Básica
curl -x [protocol://]host:port URL
Proxy HTTP
# Solicitud simple a través de proxy
curl -x http://proxy.example.com:8080 https://httpbin.org/ip
# Con autenticación
curl -x http://user:password@proxy.example.com:8080 https://httpbin.org/ip
# O por separado
curl -x http://proxy.example.com:8080 -U user:password https://httpbin.org/ip
Proxy HTTPS
curl -x https://proxy.example.com:8080 https://httpbin.org/ip
Proxy SOCKS
# SOCKS4
curl --socks4 proxy.example.com:1080 https://httpbin.org/ip
# SOCKS4A (DNS a través de proxy)
curl --socks4a proxy.example.com:1080 https://httpbin.org/ip
# SOCKS5
curl --socks5 proxy.example.com:1080 https://httpbin.org/ip
# SOCKS5 con DNS a través de proxy (recomendado)
curl --socks5-hostname proxy.example.com:1080 https://httpbin.org/ip
Variables de Entorno
# Establecer proxy globalmente
export http_proxy=http://proxy.example.com:8080
export https_proxy=http://proxy.example.com:8080
# Ahora todas las solicitudes pasan por el proxy
curl https://httpbin.org/ip
# Ignorar proxy para ciertos hosts
export no_proxy=localhost,127.0.0.1,.internal.com
Opciones Útiles
# Mostrar tiempo de conexión
curl -x http://proxy:8080 -w "Time: %{time_total}s\n" https://httpbin.org/ip
# Ignorar errores SSL
curl -x http://proxy:8080 -k https://example.com
# Establecer tiempo de espera
curl -x http://proxy:8080 --connect-timeout 10 https://httpbin.org/ip
# Seguir redirecciones
curl -x http://proxy:8080 -L https://httpbin.org/redirect/3
# Guardar cookies
curl -x http://proxy:8080 -c cookies.txt https://example.com
# Enviar solicitud POST
curl -x http://proxy:8080 -X POST -d "data=value" https://httpbin.org/post
Script de Verificación de Lista de Proxies
#!/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
Depuración
# Salida detallada
curl -x http://proxy:8080 -v https://httpbin.org/ip
# Mostrar solo cabeceras
curl -x http://proxy:8080 -I https://httpbin.org/ip