Skip to content

Instantly share code, notes, and snippets.

@lukenm
Last active December 13, 2020 12:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lukenm/9542842 to your computer and use it in GitHub Desktop.
Save lukenm/9542842 to your computer and use it in GitHub Desktop.
Shell script to update global Maxmind GeoIP databases. This script can be run via cron.
#!/bin/bash
DAT_DIR=/usr/share/GeoIP
DAT_URLS="http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz"
for FILE in $DAT_DIR/*.dat; do
cp $FILE $FILE.bak
done;
for URL in $DAT_URLS; do
FILE=${URL##*/}
curl $URL | gunzip > $DAT_DIR/${FILE%.gz}
#echo $URL $DAT_DIR/${FILE%.gz}
done;
@arimolzer
Copy link

Thanks, @lukenm!

@cowgill
Copy link

cowgill commented Apr 27, 2018

Super, thanks!

I recommend using http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz instead of GeoIP.dat.gz since it includes both v4 and v6 IPs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment