Last active
August 29, 2015 14:17
-
-
Save adamwespiser/0807ded00741772d8b51 to your computer and use it in GitHub Desktop.
get the location(from whois) of all IPs along the traceroute path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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]