2024-10-11 19:37:59 -06:00
|
|
|
# routeros-geoip
|
2024-09-29 01:23:12 +00:00
|
|
|
|
2026-05-01 17:18:50 -06:00
|
|
|
Generate RouterOS address lists from GeoIP data for MikroTik routers. Supports multiple data providers for flexibility and redundancy.
|
2024-09-28 21:25:11 -06:00
|
|
|
|
2026-05-01 17:18:50 -06:00
|
|
|
## Supported Providers
|
2024-09-28 21:25:11 -06:00
|
|
|
|
2026-05-01 17:18:50 -06:00
|
|
|
| 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):
|
2024-09-28 21:25:11 -06:00
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
{
|
2026-05-01 17:18:50 -06:00
|
|
|
"list_name": "GeoBlock",
|
|
|
|
|
"provider": "ipverse",
|
2024-09-28 21:25:11 -06:00
|
|
|
"countries": [
|
2026-05-01 17:18:50 -06:00
|
|
|
"ca",
|
|
|
|
|
"au"
|
2024-09-28 21:25:11 -06:00
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2026-05-01 17:18:50 -06:00
|
|
|
### 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
|
2024-10-19 18:40:27 -06:00
|
|
|
|
|
|
|
|
```sh
|
2026-05-01 17:18:50 -06:00
|
|
|
# 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
|
|
|
|
|
...
|
2024-10-19 18:40:27 -06:00
|
|
|
```
|
|
|
|
|
|
2026-05-01 17:18:50 -06:00
|
|
|
## Adding a New Provider
|
|
|
|
|
|
|
|
|
|
Implement the `Provider` interface:
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
type Provider interface {
|
|
|
|
|
Name() string
|
|
|
|
|
FetchCIDRs(countryCode string) ([]string, error)
|
|
|
|
|
}
|
|
|
|
|
```
|
2024-10-19 18:40:27 -06:00
|
|
|
|
2026-05-01 17:18:50 -06:00
|
|
|
Then register it in `NewProvider()` in `provider.go`.
|