mondern slopify hand crafted code for the greater good.

(move from user specified blocklist download URLs to simply country codes with multiple providers available.)
This commit is contained in:
2026-05-01 17:18:50 -06:00
parent 746bb9c8b4
commit b1ed8f75ec
10 changed files with 576 additions and 105 deletions

View File

@@ -1,31 +1,76 @@
# routeros-geoip
Generate RouterOS Address Lists based on country code. This can be used for creating up to date geo-ip blocking lists which can be loaded into RouterOS.
Generate RouterOS address lists from GeoIP data for MikroTik routers. Supports multiple data providers for flexibility and redundancy.
### Create Configuration
## Supported Providers
Create a json config file containing the address lists you want to block and a URL for source information. Below is example.json
| Provider | Source | URL |
|----------|--------|-----|
| `ipverse` (default) | RIR data via GitHub | [ipverse/country-ip-blocks](https://github.com/ipverse/country-ip-blocks) |
| `ipdeny` | RIR data via ipdeny.com | [ipdeny.com](https://www.ipdeny.com/ipblocks/) |
## Configuration
Create a JSON config file specifying your list name, provider, and countries (ISO 3166-1 alpha-2 codes):
```json
{
"list_name": "GeoBlock",
"provider": "ipverse",
"countries": [
{
"name": "CANADA",
"url": "https://raw.githubusercontent.com/herrbischoff/country-ip-blocks/refs/heads/master/ipv4/ca.cidr"
},
{
"name": "AUSTRALIA",
"url": "https://raw.githubusercontent.com/herrbischoff/country-ip-blocks/refs/heads/master/ipv4/au.cidr"
}
"ca",
"au"
]
}
```
### Usage
### Configuration Fields
| Field | Required | Default | Description |
|-------|----------|---------|-------------|
| `list_name` | Yes | — | RouterOS address list name |
| `provider` | No | `ipverse` | GeoIP data provider |
| `countries` | Yes | — | ISO 3166-1 alpha-2 country codes |
## Usage
```sh
# Example usage
./routeros-geoip myAddressList example.json
# Build
go build -o routeros-geoip .
# Generate blocklist
./routeros-geoip blocklist.json
# Import on your MikroTik router
/import CountryIPBlocks.rsc
```
## Example Output
The generated `.rsc` file includes metadata headers and cleans up old entries before importing:
```routeros
# RouterOS GeoIP Address List: CountryIPBlocks
# Generated: 2026-05-01T22:44:48Z
# Countries: 14
# Total entries: 33210
#
/ip firewall address-list remove [find list=CountryIPBlocks]
/ip firewall address-list
add address=24.152.0.0/19 comment="BRAZIL" list=CountryIPBlocks
add address=45.4.4.0/22 comment="BRAZIL" list=CountryIPBlocks
...
```
## Adding a New Provider
Implement the `Provider` interface:
```go
type Provider interface {
Name() string
FetchCIDRs(countryCode string) ([]string, error)
}
```
Then register it in `NewProvider()` in `provider.go`.