ホーム / ユースケース / curl
curl でプロキシを使う方法
curl は HTTP・HTTPS・SOCKS プロキシをネイティブに扱います。各種別の正確なフラグと、毎時検証の無料一覧から直接プロキシを取るコマンドを紹介します。
各プロキシ種別のフラグ
| プロキシ種別 | curl コマンド |
|---|---|
| HTTP / HTTPS | curl -x http://host:port URL |
| SOCKS5(リモート DNS) | curl --socks5-hostname host:port URL |
| SOCKS5(ローカル DNS) | curl --socks5 host:port URL |
| SOCKS4 | curl --socks4 host:port URL |
死んだプロキシで固まらないよう、必ず --max-time 10 を付けてください。
環境変数
export http_proxy="http://1.2.3.4:8080" export https_proxy="http://1.2.3.4:8080" curl -I "https://example.com/"
使えるプロキシを 1 行で取得
proxy="$(curl -sL https://raw.githubusercontent.com/xyzs996/free-proxy-health-list/main/proxies/protocols/http/data.txt | head -n 1)" curl -x "http://$proxy" -I "https://example.com/" --max-time 10
よくある質問
--socks5 と --socks5-hostname どちら?
--socks5 は DNS をローカル解決、--socks5-hostname はプロキシ経由。DNS 漏れを避けるため後者を推奨。
curl がプロキシで固まる時は?
--max-time を追加。無料プロキシは死ぬので早めにタイムアウトして次へ。
スクリプトなしでプロキシをテストできる?
はい — コマンド生成ツールが実行可能な curl を作ります。