Skip to content

Instantly share code, notes, and snippets.

@paulhomes
Created January 28, 2023 23:48
Show Gist options
  • Save paulhomes/1fee43e7ebee4ddfe700279f431b502e to your computer and use it in GitHub Desktop.
Save paulhomes/1fee43e7ebee4ddfe700279f431b502e to your computer and use it in GitHub Desktop.
A geoiplookup replacement that uses mmdblookup.
#!/bin/sh
ip=$1
if [ -z "$ip" ]; then
echo "ERROR: ip not specified"
echo "e.g. geoiplookup 1.1.1.1"
exit 1
fi
db=/usr/share/GeoIP/GeoIP2-Country.mmdb
code=`mmdblookup -f $db -i $ip country iso_code | tr -d '\n' | awk -F '"' '{print $2}'`
country=`mmdblookup -f $db -i $ip country names en | tr -d '\n' | awk -F '"' '{print $2}'`
echo "GeoIP Country Edition: $code, $country"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment