Skip to content

Instantly share code, notes, and snippets.

@kerolasa
Created May 20, 2021 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kerolasa/6d8bb777f0e2e9a1b73b7fe00801ccb1 to your computer and use it in GitHub Desktop.
Save kerolasa/6d8bb777f0e2e9a1b73b7fe00801ccb1 to your computer and use it in GitHub Desktop.
mmdb content export / dump in golang
package main
import (
"fmt"
"os"
maxminddb "github.com/oschwald/maxminddb-golang"
)
func main() {
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "Usage: %s ./file.mmdb\n", os.Args[0])
os.Exit(1)
}
db, err := maxminddb.Open(os.Args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "%s: %s\n", os.Args[0], err)
os.Exit(1)
}
defer db.Close()
n := db.Networks()
maxminddb.SkipAliasedNetworks(n)
for n.Next() {
var rec interface{}
cidr, err := n.Network(&rec)
if err == nil {
fmt.Printf("network: %v record: %v\n", cidr, rec)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment