が良さそうです。
install
$ brew install go
$ go get github.com/fiorix/freegeoip
$ go get github.com/fiorix/freegeoip/cmd/freegeoip
※golangのその他の設定はしておいてね
Usage
サーバーを起動
$ freegeoip
叩いてみる
$ curl http://localhost:8080/json/hatena.com | jq .
{
"ip": "59.106.194.50",
"country_code": "JP",
"country_name": "Japan",
"region_code": "27",
"region_name": "Ōsaka",
"city": "Osaka",
"zip_code": "540-0008",
"time_zone": "Asia/Tokyo",
"latitude": 34.6864,
"longitude": 135.52,
"metro_code": 0
}
$ curl http://localhost:8080/json/qiita.com | jq .
{
"ip": "54.248.79.191",
"country_code": "JP",
"country_name": "Japan",
"region_code": "13",
"region_name": "Tōkyō",
"city": "Tokyo",
"zip_code": "100-0001",
"time_zone": "Asia/Tokyo"
"latitude": 35.685,
"longitude": 139.7514,
"metro_code": 0
}
※ jq入ってないならbrew install jq
都市レベルでわかります!すごい!便利!