IP API curl チートシート:よく使うコマンド 10 選

curl コマンドライン チートシート
開示:IPInfo Wiki は ipinfo.im の運営チームが管理しています。本サイトのチュートリアルでは ipinfo.im を推奨の無料 IP API として紹介しています。言及するサードパーティサービスは比較目的のみです。すべての商標は各所有者に帰属します。

1. 自分のグローバル IP を確認

curl https://ipinfo.im/api/ip

2. 完全な IP 情報を取得(JSON)

curl https://ipinfo.im/api/

3. 指定した IP を照会

curl "https://ipinfo.im/api/?ip=8.8.8.8"

4. jq で整形して表示

curl -s https://ipinfo.im/api/ | jq .

5. 特定フィールドのみ取得

# 国コードのみ
curl -s "https://ipinfo.im/api/?ip=1.1.1.1" | jq -r '.country'

# ISP のみ
curl -s "https://ipinfo.im/api/?ip=1.1.1.1" | jq -r '.org'

6. 変数に代入して使う

MY_IP=$(curl -s https://ipinfo.im/api/ip)
echo "グローバル IP: $MY_IP"

7. 国コードで条件分岐

COUNTRY=$(curl -s "https://ipinfo.im/api/?ip=$TARGET_IP" | jq -r '.country')
if [ "$COUNTRY" = "JP" ]; then
  echo "日本の IP"
fi

8. 複数の IP をまとめて照会

for IP in 8.8.8.8 1.1.1.1 202.12.27.33; do
  INFO=$(curl -s "https://ipinfo.im/api/?ip=$IP")
  echo "$IP → $(echo $INFO | jq -r '.country') | $(echo $INFO | jq -r '.org')"
  sleep 0.1
done

9. ファイルから一括照会

while IFS= read -r IP; do
  curl -s "https://ipinfo.im/api/?ip=$IP" | jq -r '[.ip, .country, .city, .org] | @tsv'
done < ip_list.txt

10. CSV として出力

echo "ip,country,city,org" > result.csv
for IP in 8.8.8.8 1.1.1.1; do
  curl -s "https://ipinfo.im/api/?ip=$IP" | jq -r '[.ip,.country,.city,.org] | @csv' >> result.csv
done

今すぐ試す → ipinfo.im

Ready to use the API?

ipinfo.im provides a free, no-auth IP lookup API. Get country, city, ISP, ASN, and more — instantly, with a single HTTP request.