IPアドレスから国を調べてBANすることがよくあるんですが、
国を調べるところをコマンドラインで完結させることができるようです。
vim check_country.sh
---
#!/bin/sh
IP=$1
SCRIPT_PATH=`echo $(cd $(dirname $0);pwd)`
if [ "$IP" = "" ]; then
echo "usage: $0 {ip address}"
exit 1
fi
COUNTRY_CODE=`curl -s ipinfo.io/${IP}/country`
if [ "$COUNTRY_CODE" = "JP" ]; then
echo "this ip address in japan"
else
COUNTRY=`egrep "\s${COUNTRY_CODE}\s" ${SCRIPT_PATH}/data/iso3166-countrycodes.txt | awk '{print $1}'`
echo "this ip address not in japan : $COUNTRY"
fi
---
mkdir data; cd $_
wget ftp://ftp.fu-berlin.de/doc/iso/iso3166-countrycodes.txt
cd ..
chmod +x check_country.sh
./check_country.sh {ip address}


