2013-06-04 13:33:02 +00:00
|
|
|
{% extends "global/layout.html" %}
|
|
|
|
{% block title %}{% trans %}GeoIP File Specification{% endtrans %}{% endblock %}
|
2013-12-25 21:53:56 +00:00
|
|
|
{% block lastupdated %}{% trans %}December 2013{% endtrans %}{% endblock %}
|
|
|
|
{% block accuratefor %}0.9.9{% endblock %}
|
2013-05-24 17:12:20 +00:00
|
|
|
{% block content %}
|
|
|
|
|
2013-06-04 13:33:02 +00:00
|
|
|
<h2>{% trans %}Overview{% endtrans %}</h2>
|
|
|
|
<p>{% trans -%}
|
2013-05-24 17:12:20 +00:00
|
|
|
This page specifies the format of the various GeoIP files,
|
|
|
|
used by the router to look up a country for an IP.
|
2013-06-04 13:33:02 +00:00
|
|
|
{%- endtrans %}</p>
|
2013-05-24 17:12:20 +00:00
|
|
|
|
|
|
|
|
2013-06-04 13:33:02 +00:00
|
|
|
<h2>{% trans %}Country Name (countries.txt) Format{% endtrans %}</h2>
|
|
|
|
<p>{% trans -%}
|
2013-05-24 17:12:20 +00:00
|
|
|
This format is easily generated from data files available from many public sources.
|
|
|
|
For example:
|
2013-06-04 13:33:02 +00:00
|
|
|
{%- endtrans %}</p>
|
2013-06-10 07:23:39 +00:00
|
|
|
{% 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 %}
|
2013-05-24 17:12:20 +00:00
|
|
|
<ul>
|
|
|
|
<li>Encoding is UTF-8
|
|
|
|
<li>'#' in column 1 specifies a comment line
|
|
|
|
<li>Entry lines are CountryCode,CountryName
|
|
|
|
<li>CountryCode is the ISO two-letter code, upper case
|
|
|
|
<li>CountryName is in English
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
2013-06-04 13:33:02 +00:00
|
|
|
<h2>{% trans %}IPv4 (geoip.txt) Format{% endtrans %}</h2>
|
|
|
|
<p>{% trans -%}
|
2013-05-24 17:12:20 +00:00
|
|
|
This format is borrowed from Tor and is easily generated from data files available from many public sources.
|
|
|
|
For example:
|
2013-06-04 13:33:02 +00:00
|
|
|
{%- endtrans %}</p>
|
2013-06-10 07:23:39 +00:00
|
|
|
{% 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 %}
|
2013-05-24 17:12:20 +00:00
|
|
|
<ul>
|
|
|
|
<li>Encoding is ASCII
|
|
|
|
<li>'#' in column 1 specifies a comment line
|
|
|
|
<li>Entry lines are FromIP,ToIP,CountryCode
|
|
|
|
<li>FromIP and ToIP are unsigned integer representations of the 4-byte IP
|
|
|
|
<li>CountryCode is the ISO two-letter code, upper case
|
|
|
|
<li>Entry lines must be sorted by numeric FromIP
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
2013-06-04 13:33:02 +00:00
|
|
|
<h2>{% trans %}IPv6 (geoipv6.dat.gz) Format{% endtrans %}</h2>
|
|
|
|
<p>{% trans -%}
|
2013-05-24 17:12:20 +00:00
|
|
|
This is a compressed binary format designed for I2P.
|
|
|
|
The file is gzipped. Ungzipped format:
|
2013-06-04 13:33:02 +00:00
|
|
|
{%- endtrans %}</p>
|
2013-06-10 07:23:39 +00:00
|
|
|
{% highlight %}
|
2013-05-24 17:12:20 +00:00
|
|
|
Bytes 0-9: Magic number "I2PGeoIPv6"
|
|
|
|
Bytes 10-11: Version (0x0001)
|
|
|
|
Bytes 12-15 Options (0x00000000) (future use)
|
2013-12-19 12:27:57 +00:00
|
|
|
Bytes 16-23: Creation date (ms since 1970-01-01)
|
|
|
|
Bytes 24-xx: Optional comment (UTF-8) terminated by zero byte
|
2013-05-24 17:12:20 +00:00
|
|
|
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)
|
2013-06-10 07:23:39 +00:00
|
|
|
{% endhighlight %}
|
2013-06-04 13:33:02 +00:00
|
|
|
<p>{% trans %}NOTES:{% endtrans %}</p>
|
2013-05-24 17:12:20 +00:00
|
|
|
<ul>
|
|
|
|
<li>Data must be sorted (SIGNED long twos complement), no overlap.
|
2013-12-19 12:27:57 +00:00
|
|
|
So the order is 80000000 ... FFFFFFFF 00000000 ... 7FFFFFFF.
|
2013-05-24 17:12:20 +00:00
|
|
|
<li>
|
|
|
|
The GeoIPv6.java class contains a program to generate this format from
|
|
|
|
public sources such as the Maxmind GeoLite data.
|
|
|
|
<li>
|
2013-12-19 12:27:57 +00:00
|
|
|
IPv6 GeoIP lookup is supported as of release 0.9.8.
|
2013-05-24 17:12:20 +00:00
|
|
|
</ul>
|
|
|
|
{% endblock %}
|