Created
March 11, 2025 11:27
-
-
Save fatalbanana/2247dc663290b33980dd07bda1479d87 to your computer and use it in GitHub Desktop.
Convert maxmind mmdb file into map for Rspamd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"github.com/oschwald/maxminddb-golang" | |
) | |
func main() { | |
db, err := maxminddb.Open("/usr/share/GeoIP/GeoLite2-Country.mmdb") | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer db.Close() | |
record := struct { | |
Country struct { | |
ISOCode string `maxminddb:"iso_code"` | |
} `maxminddb:"country"` | |
}{} | |
networks := db.Networks(maxminddb.SkipAliasedNetworks) | |
for networks.Next() { | |
subnet, err := networks.Network(&record) | |
if err != nil { | |
log.Panic(err) | |
} | |
if record.Country.ISOCode != "" { | |
fmt.Printf("%s %s\n", subnet.String(), record.Country.ISOCode) | |
} | |
} | |
if networks.Err() != nil { | |
log.Panic(networks.Err()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment