Ubuntuでホスト名やIPアドレスから国名を調べるコマンド
GeoIPというものを使うと便利らしい。
公式サイトには各種言語用のライブラリがあるけど、今回は一番お手軽なコマンドラインから実行できるものをインストールしてみる。
インストール
$ sudo aptitude install geoip-bin
The following NEW packages will be installed:
geoip-bin
0 packages upgraded, 1 newly installed, 0 to remove and 52 not upgraded.
Need to get 42.4 kB of archives. After unpacking 190 kB will be used.
Get: 1 http://archive.ubuntu.com/ubuntu/ precise/main geoip-bin amd64 1.4.8+dfsg-2 [42.4 kB]
Fetched 42.4 kB in 0s (71.8 kB/s)
Selecting previously unselected package geoip-bin.
(Reading database ... 113025 files and directories currently installed.)
Unpacking geoip-bin (from .../geoip-bin_1.4.8+dfsg-2_amd64.deb) ...
Processing triggers for man-db ...
Setting up geoip-bin (1.4.8+dfsg-2) ...
使い方
$ geoiplookup
Usage: geoiplookup [-d custom_dir] [-f custom_file] [-v] [-i] <ipaddress|hostname>
ホスト名から
$ geoiplookup www.hatena.ne.jp
GeoIP Country Edition: JP, Japan
$ geoiplookup www.google.co.jp
GeoIP Country Edition: US, United States
$ geoiplookup www.baidu.com
GeoIP Country Edition: CN, China
$ geoiplookup line.me
GeoIP Country Edition: JP, Japan
引数にホスト名を指定するだけ。
LINEのサイトって日本サーバーなんですね。
IPアドレスから
$ geoiplookup `dig +short www.hatena.ne.jp`
GeoIP Country Edition: JP, Japan
$ geoiplookup `dig +short www.google.co.jp`
GeoIP Country Edition: US, United States
$ geoiplookup `dig +short www.baidu.com`
GeoIP Country Edition: CN, China
$ geoiplookup `dig +short line.me`
GeoIP Country Edition: JP, Japan
引数をIPアドレスにするだけ。