Last active
March 10, 2018 09:27
-
-
Save VBaczynski/757e0c16b1690ee952614fba4f36f924 to your computer and use it in GitHub Desktop.
Splitting the list of IP addresses into files by country codes
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 [ $# = 0 ]; then | |
echo | |
echo Usage example: | |
echo "sh ipbycountry.sh IPs.list" | |
echo | |
exit 1 | |
fi | |
iplist=$1 | |
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 | |
echo $IP >> $country.ips | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment