Compare commits

...

4 Commits

3 changed files with 17 additions and 10 deletions

View File

@ -1,13 +1,10 @@
# mikrotik-geoipblock
# routeros-geoip
Generate RouterOS Address Lists based on country code.
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.
```sh
# Example usage
./mikrotik-geoipblock myAddressList example.json
```
### Create Configuration
Createa a config file containing the address lists you want to block
Create a json config file containing the address lists you want to block and a URL for source information. Below is example.json
```json
{
@ -24,3 +21,11 @@ Createa a config file containing the address lists you want to block
}
```
### Usage
```sh
# Example usage
./routeros-geoip myAddressList example.json
```

2
go.mod
View File

@ -1,3 +1,3 @@
module code.stevenpolley.net/steven/mikrotik-geoipblock
module code.stevenpolley.net/steven/routeros-geoip
go 1.23.0

View File

@ -28,7 +28,6 @@ func main() {
}
blockListName := os.Args[1]
jsonListFile := os.Args[2]
fmt.Printf("generating blocklist %s\n", blockListName)
// Load blocklist config file
countries, err := readJsonListFile(jsonListFile)
@ -38,6 +37,7 @@ func main() {
// Download up to date geoip CIDR data
for i := range countries {
fmt.Println("downloading cidr list for country:", countries[i].Name)
countries[i].v4Addresses, err = downloadAddressList(countries[i].Url)
if err != nil {
log.Fatalf("failed to download address list for county'%s': %v", countries[i].Name, err)
@ -45,10 +45,12 @@ func main() {
}
// Generate mikrotik block list
fmt.Printf("generating blocklist %s.rsc\n", blockListName)
err = generateOutput(countries, blockListName)
if err != nil {
log.Fatalf("failed to generate output file: %v", err)
}
fmt.Printf("\n\nCopy the file the router, then import the address list\n\n\t/import %s.rsc\n", blockListName)
}
func generateOutput(countries []Country, blockListName string) error {
@ -81,7 +83,7 @@ func downloadAddressList(url string) ([]string, error) {
line := scanner.Text()
_, ipnet, err := net.ParseCIDR(line)
if err != nil {
log.Printf("skippine line: failed to parse line '%s' to cidr: %v", line, err)
log.Printf("skipping line: failed to parse line '%s' to cidr: %v", line, err)
continue
}
v4Addresses = append(v4Addresses, ipnet.String())