Quantcast
Channel: プログラミング
Viewing all articles
Browse latest Browse all 8415

IPアドレスから国コードをコマンドラインで取得する4つの方法 - mkdir blog && cd $_

$
0
0

IPアドレスから、どの国からアクセスしてきたかを調べたいことが多い。 いくつか実現方法があるのでメモをしておく。

IPinfo

IPinfoは会員登録不要で、無料で5万リクエスト/月まで出来る。

$ curl ipinfo.io/<IPアドレス>

e.g.)

$ curl ipinfo.io/8.8.8.8{"ip": "8.8.8.8",
  "hostname": "dns.google",
  "anycast": true,
  "city": "Mountain View",
  "region": "California",
  "country": "US",
  "loc": "37.4056,-122.0775",
  "org": "AS15169 Google LLC",
  "postal": "94043",
  "timezone": "America/Los_Angeles",
  "readme": "https://ipinfo.io/missingauth"}

ipinfo.io

ip-api

ip-apiは会員登録不要で、45リクエスト/分間まで出来る。

$ curl ip-api.com/json/<IPアドレス>
$ curl ip-api.com/json/8.8.8.8 | jq
{"status": "success",
  "country": "United States",
  "countryCode": "US",
  "region": "VA",
  "regionName": "Virginia",
  "city": "Ashburn",
  "zip": "20149",
  "lat": 39.03,
  "lon": -77.5,
  "timezone": "America/New_York",
  "isp": "Google LLC",
  "org": "Google Public DNS",
  "as": "AS15169 Google LLC",
  "query": "8.8.8.8"}

ip-api.com

ipstack

ipstackは会員登録は必要になるが、無料プランも提供されている。

$ curl http://api.ipstack.com/<IPアドレス>?access_key=<YOUR_ACCESS_KEY>

ipstack.com

whoisコマンド

$ whois <IPアドレス> | grep-i country | head -1 | awk '{print $2}'

e.g.)

$ whois 8.8.8.8 | grep-i country | head -1 | awk '{print $2}'
US

Viewing all articles
Browse latest Browse all 8415

Trending Articles