#!/bin/bash geolocate() { ip=$1 (wget -O - -q "http://api.hostip.info/get_html.php?ip=$ip";echo "") |( while read key value; do case $key in "Country:") country=$value ;; "City:") city=$value ;; esac done if [ "$city" != "(Unknown City?)" -a "$city" != "(Unknown city)" -a "$city" != "(Private Address)" ]; then echo " $city $country " elif [ "$country" != "(Unknown Country?) (XX)" -a "$country" != "(Private Address) (XX)" ]; then echo " $country" else echo "" fi ) } traceroute $* |( while read line; do if [ `echo "$line" | egrep -c "^[[:space:]]*[[:digit:]]+[[:space:]]+[^ ]*[[:space:]]+\([^ )]*\)"` -gt 0 ]; then ip=`echo "$line" |sed "s/^ *[0-9]\+ \+[^ ]* \+(\([^)]\+\)).*/\1/"` elif [ `echo "$line" | egrep -c "[[:space:]]*[[:digit:]]+[[:space:]]+[^ ]*[[:space:]]+[^\(]"` -gt 0 ]; then ip=`echo "$line" |sed "s/^ *[0-9]\+ \+\([^ ]\+\).*/\1/"` else ip="" fi echo -n "$line" if [ "$ip" != "" ]; then geolocate "$ip" fi done )