geoip
Simple command line utility to parse a local MaxMind GeoIP2 mmdb (leveraging the great oschwald/geoip2-golang library,
and use it to enrich a CSV containing an IP address. It currently adds columns for city
, country
, isAnonymousIP
,
and isSatelliteProvider
.
It's intentionally designed as a typical *nix
cli tool, reading from stdin
and writing to stdout
.
Installing
Installing currently requires Go to be installed
go get github.com/sbogacz/geoip
Example
echo "8.8.8.8" | geoip
8.8.8.8,,United States,false,false
By default it expects the first column to contain the IP address, but that behavior is configurable with the -i
flag.
echo "default,dnsserver,8.8.8.8" | geoip -i 2
default,dnsserver,8.8.8.8,,United States,false,false
If the address is quoted in some way, the quoting character can be specified with -c
echo 'default,dnsserver,"8.8.8.8"' | geoip -i 2 -c '"'
default,dnsserver,"8.8.8.8",,United States,false,false
Getting the GeoIP2 Database on Mac OS
- Sign up for the free GeoLite2 DB access
- Once you have an account, configure a license key for the new database format
- Once generated, either download the generated
.conf
file, or copy the license key and your account ID to a separate file
- (Mac OS)
brew install geoipupdate
- (Optional) Configure
geoipupdate
by either copying the generated .conf
file above to its default location (can be obtained with -h
) or editing
the existing file with the copied values from step 3.
- Run
geoipupdate
Et voila!