geolist
A simple Go utility to extract all IP network ranges for a given 2-letter country code or ASN from a MaxMind GeoIP2/GeoLite2 database and write them to a text file.
The output could be used to blacklist a country or asn in haproxy for example. It looks like this:
1.178.64.0/23
1.178.68.0/22
1.178.72.0/21
1.178.81.0/24
1.178.86.0/23
1.178.88.0/21
1.178.100.0/22
1.178.104.0/21
1.178.144.0/20
1.178.160.0/25
[...]
Prerequisites
A MaxMind GeoIP2 or GeoLite2 database file (City and/or ASN).
I recommend using geoipupdate to keep the databases up to date.
Installation
Example for Linux amd64:
wget https://git.rznet.fr/tchivert/geolist/releases/download/latest/geolist-linux-amd64 -O /usr/local/bin/geolist
chmod +x /usr/local/bin/geolist
Check the release page for other architectures.
Usage
Usage of geolist:
-a ASN numbers
-adb ASN DB (default "/var/lib/GeoIP/GeoLite2-ASN.mmdb")
-c 2-letter country codes
-cdb City DB (default "/var/lib/GeoIP/GeoLite2-City.mmdb")
-4 IPv4 only
-6 IPv6 only
-o Output text file
Command-line flags
One of the following flags is required, and both can be used together:
-c: 2-letter country code (e.g.,US,FR,JP), or a comma-separated list of country codes (e.g.,US,FR,JP)-a: ASN number (e.g.,12345), or a comma-separated list of ASN numbers (e.g.,12345,67890)
The following flags are optional:
-o: Path to the output text file where matching CIDRs will be written-4: Only output IPv4 CIDRs-6: Only output IPv6 CIDRs-cdb: Path to the MaxMindGeoLite2-City.mmdbdatabase file (default/var/lib/GeoIP/GeoLite2-City.mmdb)-adb: Path to the MaxMindGeoLite2-ASN.mmdbdatabase file (default/var/lib/GeoIP/GeoLite2-ASN.mmdb)
Example
Dump all IP ranges for the United States into us_ranges.txt:
./geolist -c US -cdb /var/lib/GeoIP/GeoLite2-City.mmdb -o us_ranges.txt
Or all IP ranges of a specific AS (AS14061 for example):
./geolist -a 14061 -adb /var/lib/GeoIP/GeoLite2-ASN.mmdb -o digitalocean_ips.txt
License
This project is licensed under the MIT License. See the LICENSE file for more information.