tchivert d00acb153f
build / build (push) Successful in 37s
add ipv4 and ipv6 filters
2025-05-12 12:43:19 +02:00
2025-05-02 11:31:20 +02:00
2025-05-12 12:43:19 +02:00
2025-05-02 14:54:50 +02:00
2025-05-02 14:54:50 +02:00
2025-05-02 11:51:02 +02:00
2025-05-12 12:43:19 +02:00

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

./geolist [-c <COUNTRY_CODE> | -a <ASN>] [-4 | -6] [-cdb <CITY_MMDB>] [-adb <ASN_MMDB>] [-o <OUTPUT_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 MaxMind GeoLite2-City.mmdb database file (default /var/lib/GeoIP/GeoLite2-City.mmdb)
  • -adb : Path to the MaxMind GeoLite2-ASN.mmdb database 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.

Description
No description provided
Readme MIT 179 KiB
latest Latest
2025-05-12 10:43:19 +00:00
Languages
Go 100%