Created
January 28, 2023 23:48
-
-
Save paulhomes/1fee43e7ebee4ddfe700279f431b502e to your computer and use it in GitHub Desktop.
A geoiplookup replacement that uses mmdblookup.
This file contains 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/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