hackrepair

IP address to country sorting bash script

Oct 14th, 2015
461
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