Skip to content

Instantly share code, notes, and snippets.

@palaniraja
Created May 12, 2014 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palaniraja/a9bf0f18e6e9d299cfc2 to your computer and use it in GitHub Desktop.
Save palaniraja/a9bf0f18e6e9d299cfc2 to your computer and use it in GitHub Desktop.
Check city or country for list of IP using ipinfo.io

To find country names of all the ips in ips.txt

./ipinfo.sh country ips.txt will append all the countries to a out.txt file

cat out.txt | sort u will list all unique countries/list from the list

To find city names of all the ips in ips.txt

./ipinfo.sh city ips.txt

#!/bin/bash
# Usage: ./ipinfo.sh country|city file_containing_one_ip_per_line
# Thank you ipinfo.io
filename=$2
ipAddresses=`cat $filename`
`echo "" > out.txt` #To empty the file
for ip in $ipAddresses
do
cmd="curl -s ipinfo.io/${ip}/${1}"
#echo $cmd
output=$(`$cmd >> out.txt`)
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment