Skip to content

Instantly share code, notes, and snippets.

@myouju
Created February 29, 2016 10:27
Show Gist options
  • Select an option

  • Save myouju/dc264ad14e96b7492b84 to your computer and use it in GitHub Desktop.

Select an option

Save myouju/dc264ad14e96b7492b84 to your computer and use it in GitHub Desktop.
ip listからgeoipを使って国名を取得する
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
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