GeoIP.dat.gz and GeoLiteCity.dat.gz not longer available? Getting 404 trying to load it

Viewed 32812
5 Answers

You can convert MaxMind GeoLite2 Database to the old legacy format with this script:

Example: ./geolite2legacy.py -i GeoLite2-Country-CSV.zip -f geoname2fips.csv -o GeoIP.dat

BTW - there is a site where you can find new data on the legacy format, here: https://www.miyuru.lk/geoiplegacy (the files there were built using with this script)

I use awk to parse country and network information from whois.

#!/bin/bash
IP=$1

if out=$(grep $IP /tmp/mygeoip)
then
    echo "$out" | awk '{$1="";print}'
    exit
fi

if [[ ($IP =~ ^10\.) || ($IP =~ ^192.168\.) || ($IP =~ ^172.16\.) ]]
then
    echo "LAN"
    exit 0
fi

#  __^__             __^__
# ( ___ )-----------( ___ )
#  | / | AWK version | \ |
#  |___|             |___|
# (_____)-----------(_____)

result=$(whois $IP | awk '/country/ {country=$2} /netname/ {netname=$2} END {print country,netname}')
echo $IP $result >> /tmp/mygeoip
echo $result

$ net.ip.geo 192.168.90.238
LAN
$ net.ip.geo 92.247.20.226
BG MTELNET
$ net.ip.geo 129.45.92.28
DZ Optimum-Telecom-Algeria
$

It uses a temporary cache in /tmp/mygeoip so that query on same IP is looked up in the cache not from whois.

Related