Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- ########################################################################
- #
- # country
- # Get countryname for IP-address if possible
- #
- # Requires perl and installed Locale::Code.
- # On debianoid systems, apt-get install liblocale-codes-perl!
- # It isn't installed by default.
- #
- # $Id: country,v 1.2 2020/11/13 13:18:49 elias Exp $
- #
- ########################################################################
- export PATH=/bin:/usr/bin
- errc=0
- for ip
- do
- code=`whois $ip | grep -i ^country | sed 's/^[^:]*:\s*//'`
- if [ -z "$code" ]
- then
- echo "No country known for $ip" 1>&2
- errc=`expr $errc + 1`
- else
- echo -n "$ip is from "
- # Sometimes, there are more than one country in the whois
- # record for an IP, therefore the funny loop.
- # Would be nice to eliminate doubles, but I use my scripts
- # and enhance them later if needed.
- for i in $code
- do
- cntry=`perl -M'Locale::Country' -e "print code2country('$i');"`
- echo -n "$cntry ($i) "
- done
- echo ""
- fi
- done
- if [ $errc -eq 0 ]
- then
- exit 0
- else
- echo "$errc error(s) occured" 1>&2
- exit 1
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement