Last active
December 13, 2020 12:03
-
-
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.
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
#!/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; |
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
Thanks, @lukenm!