Created
March 10, 2018 09:32
-
-
Save VBaczynski/6371a2e65e187aa7f2bbfdc85ea7e0d0 to your computer and use it in GitHub Desktop.
Selection of country-specific IP addresses
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 | |
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin | |
if [ $# != 2 ]; then | |
echo | |
echo Usage example: | |
echo "sh ip2country.sh IPs.list US" | |
echo | |
exit 1 | |
fi | |
iplist=$1 | |
ccode=$2 | |
for IP in `cat $iplist` | |
do | |
country=`geoiplookup "$IP" | head -1 | awk '{print $4}' | cut -d , -f1` | |
if [ "x$country" = 'x' ]; then | |
# If the IP address does not belong to any country (not in the database) | |
country="XX" | |
fi | |
if [ "$country" = "$ccode" ]; then | |
echo $IP >> $ccode.ips | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment