From 4914877d04788cb41a3a161f6c0f2edfb3193c83 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 15 Apr 2013 21:30:51 +0100 Subject: [PATCH] Add geoiptool command --- bin/geoiptool | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 bin/geoiptool diff --git a/bin/geoiptool b/bin/geoiptool new file mode 100755 index 0000000..4c8eeb5 --- /dev/null +++ b/bin/geoiptool @@ -0,0 +1,44 @@ +#! /usr/bin/env bash +# +# geoiptool +# +# A quick and dirty shell script to easily extract data from geoiptool.com. +# Use, modify, copy, steal, and/or plunder this command to your hearts +# content, at your own risk of course :) --jimeh +# + + +padlen=13 +ipaddress=$1 + +if [[ "$1" == "--raw" ]] || [[ "$1" == "-r" ]]; then + padlen=0 + ipaddress=$2 +elif [[ "$2" == "--raw" ]] || [[ "$2" == "-r" ]]; then + padlen=0 +fi + +case "$1" in + "-h" | "--help" ) + echo "usage: geoiptool []" + echo "" + echo "Options:" + echo " --raw, -r: Do not align headers. Allows easier machine parsing of output." + echo "" + echo "Look up details for given IP address via http://www.geoiptool.com/. If no IP" + echo "address is given, your own public IP will be used instead." + ;; + * ) + curl -s "http://www.geoiptool.com/en/?IP=${ipaddress}" -H "User-Agent: " | \ + awk -F '(]+>)+' \ + "/Host Name/,/Latitude/ { + if (/:/) { + printf(\"%${padlen}s \", \$2); + getline; + gsub(/^[ \t]+/, \"\", \$2); + gsub(/[ \t]+$/, \"\", \$2); + print \$2 + } + }" + ;; +esac