{% extends "global/layout.html" %} {% block title %}{% trans %}GeoIP File Specification{% endtrans %}{% endblock %} {% block lastupdated %}{% trans %}May 2013{% endtrans %}{% endblock %} {% block accuratefor %}0.9.6{% endblock %} {% block content %}

{% trans %}Overview{% endtrans %}

{% trans -%} This page specifies the format of the various GeoIP files, used by the router to look up a country for an IP. {%- endtrans %}

{% trans %}Country Name (countries.txt) Format{% endtrans %}

{% trans -%} This format is easily generated from data files available from many public sources. For example: {%- endtrans %}

{% highlight lang='bash' %} $ wget http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip $ unzip GeoIPCountryCSV.zip $ cut -d, -f5,6 < GeoIPCountryWhois.csv |sed 's/"//g' | sort | uniq > countries.txt {% endhighlight %}

{% trans %}IPv4 (geoip.txt) Format{% endtrans %}

{% trans -%} This format is borrowed from Tor and is easily generated from data files available from many public sources. For example: {%- endtrans %}

{% highlight lang='bash' %} $ wget http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip $ unzip GeoIPCountryCSV.zip $ cut -d, -f3-5 < GeoIPCountryWhois.csv|sed 's/"//g' > geoip.txt $ cut -d, -f5,6 < GeoIPCountryWhois.csv |sed 's/"//g' | sort | uniq > countries.txt {% endhighlight %}

{% trans %}IPv6 (geoipv6.dat.gz) Format{% endtrans %}

{% trans -%} This is a compressed binary format designed for I2P. The file is gzipped. Ungzipped format: {%- endtrans %}

{% highlight %} Bytes 0-9: Magic number "I2PGeoIPv6" Bytes 10-11: Version (0x0001) Bytes 12-15 Options (0x00000000) (future use) Bytes 16-23: Creation date (Java long) Bytes 24-xx: Optional comment (UTF-8) Bytes xx-255: null padding Bytes 256-: 18 byte records: 8 byte from (/64) 8 byte to (/64) 2 byte ISO country code LOWER case (ASCII) {% endhighlight %}

{% trans %}NOTES:{% endtrans %}

{% endblock %}