Skip to content

Instantly share code, notes, and snippets.

@adamwespiser adamwespiser/tracerouteLoc
Last active Aug 29, 2015

Embed
What would you like to do?
get the location(from whois) of all IPs along the traceroute path
#!/bin/bash
# tracerouteLoc: A tool to get city/state information from IP addr in traceroute
#Copyright (C) 2015 Adam Wespiser
#
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
# ensure the first arg is set
if [ -v $1 ]; then
echo "USAGE:"
echo "$ tracerouteLoc [website URL]"
exit
fi
# make sure user has traceroute installed
if [[ ! -e $(which traceroute) ]]; then
echo "must install traceroute"
echo "$ sudo apt-get install traceroute"
exit
fi
# make sure use has whois installed
if [[ ! -e $(which whois) ]]; then
echo "must install whois"
echo "$ sudo apt-get install whois"
exit
fi
# run traceroute
traceroute $1 2>1 \
# get perl to print out IP addrs from each line
| perl -e 'while(<>){
if ($_ =~ m/\(([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\)/g){
print $1."\n";
}
}' \
# pipe into whois via xargs
| xargs -I{} whois {} \
# pull out lines starting with City, State, or '#' (used to delineate entries)
| grep '^City\|^State\|^#$'\
# condense duplicate entries per result
| uniq
@adamwespiser

This comment has been minimized.

Copy link
Owner Author

commented Mar 27, 2015

Prerequisites:
To run, you must install traceroute,
$ sudo apt-get install traceroute
$ sudo apt-get install whois

Installation:
$ wget https://gist.githubusercontent.com/adamwespiser/0807ded00741772d8b51/raw/de580acfb5fbbebb54afdec484d864e674b7550a/tracerouteLoc -O tracerouteLoc
$ chmod u+x tracerouteLoc

Invocation:
$ tracerouteLoc [website URL]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.