82 lines
2.3 KiB
Markdown
82 lines
2.3 KiB
Markdown
# 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](https://github.com/maxmind/geoipupdate) to keep the databases up to date.
|
|
|
|
## Installation
|
|
|
|
Example for Linux amd64:
|
|
|
|
```bash
|
|
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 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`:
|
|
|
|
```bash
|
|
./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):
|
|
|
|
```bash
|
|
./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](https://git.rznet.fr/tchivert/geolist/src/branch/main/LICENSE) file for more information.
|