Created
February 29, 2016 10:27
-
-
Save myouju/dc264ad14e96b7492b84 to your computer and use it in GitHub Desktop.
ip listからgeoipを使って国名を取得する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM ubuntu-debootstrap:14.04 | |
| MAINTAINER yuki-maeno | |
| RUN echo "Asia/Tokyo" > /etc/timezone && dpkg-reconfigure --frontend noninteractive tzdata \ | |
| && apt-get update \ | |
| && apt-get install --no-install-recommends -y git python python-pip liblua5.1-dev libssl-dev python-dev libevent-dev libgeoip-dev wget build-essential \ | |
| && apt-get clean \ | |
| && rm -fr /var/cache/apt/archives/* /var/lib/apt/lists/* | |
| RUN wget https://pypi.python.org/packages/source/G/GeoIP/GeoIP-1.3.2.tar.gz \ | |
| && tar zxvf GeoIP-1.3.2.tar.gz \ | |
| && cd GeoIP-1.3.2 \ | |
| && python setup.py build \ | |
| && python setup.py install | |
| WORKDIR / | |
| RUN wget -N http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz \ | |
| && gzip -d GeoIP.dat.gz \ | |
| && mkdir -p /usr/share/GeoIP \ | |
| && mv GeoIP.dat /usr/share/GeoIP/ | |
| ADD geo.py geo.py | |
| ADD ip.list ip.list |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import print_function | |
| import GeoIP | |
| gi = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE) | |
| f = open("ip.list") | |
| line = f.readline() | |
| while line: | |
| line = line.strip() | |
| cn = gi.country_name_by_addr(line) | |
| print(str(line) + "\t" + cn) | |
| line = f.readline() | |
| f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment