SHARE
TWEET

IP address to country sorting bash script

hackrepair Oct 14th, 2015 (edited) 451 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #IP address to country sorting, by Jim Walker, HackRepair.com
  2. #./geoiplookup [IP] or ./geoiplookup [filename]
  3. #!/bin/bash
  4. INPUT=$1
  5. if [ -f $INPUT ];
  6. then
  7. while read -r ip
  8. do
  9.                 LOOKUP="$(geoiplookup ${ip})"
  10.                 COUNTRY="$(echo "${LOOKUP}"|awk -F: '{ print $2 }'|awk -F, '{ print $1 }')"
  11.                 echo "${COUNTRY} ${ip}"
  12. done < "$INPUT"
  13. else
  14.                 LOOKUP="$(geoiplookup $INPUT)"
  15.                 COUNTRY="$(echo "${LOOKUP}"|awk -F: '{ print $2 }'|awk -F, '{ print $1 }')"
  16.                 echo "${COUNTRY} $INPUT"
  17. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top