A MaxMind DB reader in Julia
MaxMind DB binary files store data indexed by IP address subnets.
This package implements version 2 of the format and it can handle both IPv4 or IPv6 databases with record sizes of 24, 28 or 32 bits.
To install from GitHub:
] add https://github.com/lbilli/MMDBReader.jl
To look up an IP address in a database:
using MMDBReader: MMDBReader as MM
filename = "/path/to/file.mmdb"
ip = "8.8.8.8" or "2001:4860:4860::8888"
# Load a database file
db = MM.loaddb(filename)
# Look up an IP
res, prefix = MM.lookup(db, ip)
# Return the database metadata
meta = MM.metadata(db)
Results are typically kay/value maps, possibly nested,
and are presented here as Julia's Dict{String,Any}
.
Supported data types are mapped to Julia builtin types according to the following table:
MaxMind DB | Julia |
---|---|
UTF-8 string | String |
double | Float64 |
bytes | UInt8[] |
unsigned 16-bit int | UInt16 |
unsigned 32-bit int | UInt32 |
signed 32-bit int | Int32 |
unsigned 64-bit int | UInt64 |
unsigned 128-bit int | UInt128 |
map | Dict{String,Any} 1 |
array | Vector{Any} 1 |
boolean | Bool |
float | Float32 |