GeoIP

表題の件について。ふとしたことから`geoiplookup`なるコマンドの存在を知ったので試してみた。

■ 環境

  • GeoIP 1.4.8
  • Amazon Linux

■ GeoIP

AmazonLinuxでパッケージがあるのか確認。

$ sudo yum search geoip
読み込んだプラグイン:priorities, update-motd, upgrade-helper
========== N/S matched: geoip==========
GeoIP-devel.x86_64 : Development headers and libraries for GeoIP
lighttpd-mod_geoip.x86_64 : GeoIP module for lighttpd to use for location lookups
mod24_geoip.x86_64 : GeoIP module for the Apache HTTP Server
mod_geoip.x86_64 : GeoIP module for the Apache HTTP Server
nginx-mod-http-geoip.x86_64 : Nginx HTTP geoip module
GeoIP.i686 : C library for country/city/organization to IP address or hostname mapping
GeoIP.x86_64 : C library for country/city/organization to IP address or hostname mapping

  Name and summary matches only, use "search all" for everything.
$

名前から察するに”GeoIP“であろう。確認する。

$ sudo yum info GeoIP
読み込んだプラグイン:priorities, update-motd, upgrade-helper
利用可能なパッケージ
名前                : GeoIP
アーキテクチャー    : i686
バージョン          : 1.4.8
リリース            : 1.5.amzn1
容量                : 780 k
リポジトリー        : amzn-main/latest
要約                : C library for country/city/organization to IP address or hostname mapping
URL                 : http://www.maxmind.com/app/c
ライセンス          : LGPLv2+
説明                : GeoIP is a C library that enables the user to find the country that any IP
                    : address or hostname originates from. It uses a file based database that is
                    : accurate as of March 2003. This database simply contains IP blocks as keys, and
                    : countries as values. This database should be more complete and accurate than
                    : using reverse DNS lookups.

名前                : GeoIP
アーキテクチャー    : x86_64
バージョン          : 1.4.8
リリース            : 1.5.amzn1
容量                : 783 k
リポジトリー        : amzn-main/latest
要約                : C library for country/city/organization to IP address or hostname mapping
URL                 : http://www.maxmind.com/app/c
ライセンス          : LGPLv2+
説明                : GeoIP is a C library that enables the user to find the country that any IP
                    : address or hostname originates from. It uses a file based database that is
                    : accurate as of March 2003. This database simply contains IP blocks as keys, and
                    : countries as values. This database should be more complete and accurate than
                    : using reverse DNS lookups.

$

インストールする。

$ sudo yum install GeoIP

インストールされたモジュールを確認する。

$ rpm -ql GeoIP
/etc/GeoIP.conf
/etc/GeoIP.conf.default
/usr/bin/geoiplookup
/usr/bin/geoiplookup6
/usr/bin/geoipupdate
/usr/lib64/libGeoIP.so.1
/usr/lib64/libGeoIP.so.1.4.8
/usr/lib64/libGeoIPUpdate.so.0
/usr/lib64/libGeoIPUpdate.so.0.0.0
/usr/share/GeoIP
/usr/share/GeoIP/GeoIP.dat
/usr/share/doc/GeoIP-1.4.8
/usr/share/doc/GeoIP-1.4.8/AUTHORS
/usr/share/doc/GeoIP-1.4.8/COPYING
/usr/share/doc/GeoIP-1.4.8/ChangeLog
/usr/share/doc/GeoIP-1.4.8/INSTALL
/usr/share/doc/GeoIP-1.4.8/LICENSE.txt
/usr/share/doc/GeoIP-1.4.8/README
/usr/share/doc/GeoIP-1.4.8/TODO
/usr/share/doc/GeoIP-1.4.8/fetch-geoipdata-city.pl
/usr/share/doc/GeoIP-1.4.8/fetch-geoipdata.pl
/usr/share/man/man1/geoiplookup.1.gz
/usr/share/man/man1/geoiplookup6.1.gz
/usr/share/man/man1/geoipupdate.1.gz
$

お望みの`geoiplookup`コマンドがインストールされたようである。では早速自身が管理しているとあるサイトで試してみる。

$ geoiplookup www.example.com
GeoIP Country Edition: US, United States
$

ここで”JP“が返ってくると思っていたのだが、想定外の”US“が返ってきた。さてどういう事だろうか?としばし考えると、このドメインに指定しているIPは最近取得したものであった事を思い出した。インストールされている”GeoIP.dat“のデータが古いのであろうと予想し、前述のモジュール一覧にもあった”GeoIP.dat“ファイルを更新する事にした。

GeoLite Legacy Downloadable Databases << Maxmind Developer Site
http://dev.maxmind.com/geoip/legacy/geolite/

上記より”GeoLote Country“の”Binary/gzip“をダウンロードし、前述の場所に展開する。もともとインストールされたものは2012年のものであったようである。

$ pwd
/usr/share/GeoIP
$ sudo wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
$ gunzip GeoIP.dat.gz
$ ls -l
-rw-rw-r-- 1 root root 1072823 Feb  8 05:22 GeoIP.dat
-rw-r--r-- 1 root root 1183408 Jan 26  2012 GeoIP.dat.old
$

再度`geoiplookup`コマンドを試してみる。

$ geoiplookup www.example.com
GeoIP Country Edition: JP, Japan
$

思い通りの結果が得られたようである。ちなみに”GeoIP.dat“は毎月第一火曜日に更新されるようだ。

さらに`geoiplookup6`というコマンドもあるが、これも前述のページより”GeoIPv6.dat“をダウンロードし配置したところ使用可能となった。

以上。

コメントを残す

メールアドレスが公開されることはありません。

CAPTCHA


このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください