#!/bin/sh # # Use geotraceroute to fetch traceroutes to all hosts used to view a web page and print KML # output for all traces. usage() { cat < EOF } gtrnode=4 if [ "$1" ]; then har="$1" else usage exit 1 fi har2hosts() { jq -r '.log | .entries | map(.request) | map(.url) | join("\n")' < $har | grep ^http | cut -d/ -f3 | sort -u } kmljoin() { cat $* | perl -e '$line = ""; while (<>) { $line .= $_; }; $line =~ s%\s\s<\?xml version="1.0" encoding="UTF-8"\?>\s\s\sGenerated by https://geotraceroute.com%%gs; $line =~ s%.+%%g; print $line;' } if [ ! -d cache ] ; then mkdir cache ; fi for h in $(har2hosts) ; do kml="cache/$h.kml" if [ ! -f "$kml" ] ; then curl -s "https://www.geotraceroute.com/petter.php?node=$gtrnode&host=$h" > "$kml" fi kmls="$kmls $kml" done kmljoin $kmls