# MaxmindDB lookup bash alias - Requires python3-maxmind
#
# Example use:
# - single ip: geoip 8.8.8.8
# - ip list: for i in `cat ip.txt` ; do printf "%s,%s\n" "$i" "`geoip \"$i\"`" ; done
#
alias geoip=$'python3 -c "import sys,maxminddb\ntry:\n print(maxminddb.open_database(\\\"/var/lib/GeoIP/GeoLite2-Country.mmdb\\\").get(sys.argv[1])[\\\"country\\\"][\\\"names\\\"][\\\"en\\\"])\nexcept:\n print(\\\"Error\\\")"'
# Same but switching quote marks to make it multi-line and easier to read
alias geoip="python3 -c \"import sys,maxminddb
try:
print(maxminddb.open_database('/var/lib/GeoIP/GeoLite2-Country.mmdb').get(sys.argv[1])['country']['names']['en'])
except:
print('Error')\""
Comments
0 B
|👍
/👎