1001001

73。CTFのWrite-upから始まったけど最近は技術全般の備忘録となっています。

【Python,Cygwin】GeoIPでIPから国名などの情報を取得

取り急ぎメモ.

環境

Windows, Cygwin, Python2.7

インストール

libGeoIP-develが必要.

管理者権限でCygwinを起動して以下を実行.

$ apt-cyg install libGeoIP-devel
hash_check: sha512sum: GeoIP-database-20161207-1.tar.xz: OK
Unpacking...
Package GeoIP-database installed
Package cygwin is already installed, skipping
Package libGeoIP1 installed
Package pkg-config is already installed, skipping
Running postinstall scripts
Package libGeoIP-devel installed

$ pip install GeoIP Collecting GeoIP Using cached GeoIP-1.3.2.tar.gz Installing collected packages: GeoIP Running setup.py install for GeoIP ... done Successfully installed GeoIP-1.3.2</pre> <h3> 実行確認</h3> <pre class="theme:dark-terminal lang:default decode:true">$ python Python 2.7.10 (default, Jun 1 2015, 18:17:45) [GCC 4.9.2] on cygwin Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; import GepIP Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ImportError: No module named GepIP &gt;&gt;&gt; import GeoIP &gt;&gt;&gt; gi = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE) &gt;&gt;&gt; gi.country_code_by_name("yahoo.com") 'US' &gt;&gt;&gt; gi.country_code_by_addr("107.189.171.198") 'US'</pre> <h4> 参考</h4> <ul> <li><a href="GeoIP">http://sonickun.hatenablog.com/entry/2014/07/30/211426">GeoIPIPアドレスから位置情報を取得する[Python]</a></li> </ul>