Skip to content

Instantly share code, notes, and snippets.

@VBaczynski
Last active March 10, 2018 09:27
Show Gist options
  • Save VBaczynski/757e0c16b1690ee952614fba4f36f924 to your computer and use it in GitHub Desktop.
Save VBaczynski/757e0c16b1690ee952614fba4f36f924 to your computer and use it in GitHub Desktop.
Splitting the list of IP addresses into files by country codes
#!/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