Table of Contents

, , , ,

whois lookup on list of IPs and find countries

For a list of IPs in file like this:

115.73.43.82
171.226.37.107
116.100.13.224
171.252.244.192
27.75.96.60
115.73.181.107
27.64.204.111
116.177.225.197
27.65.174.108
115.72.36.7
...

do a lookup with whois

for ip in $(cat list);do whois $ip |awk -F: '/country/ {print $2}'| sort;done > sorted1.txt

Then show sorted and aggregated.

cat sorted1.txt |sort|uniq -c

If you get an error like:

No whois server is known for this kind of object.

Could be the input file is messed up. Use this command instead:

while IFS=$' \t\r\n' read -r ip; do whois $ip |awk -F: '/country/ {print $2}'| sort; done < list > sorted

Tested on

See also

References