You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

40 lines
966 B

#!/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
Usage: $0 <har-file>
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%</Document>\s</kml>\s<\?xml version="1.0" encoding="UTF-8"\?>\s<kml xmlns="http://www.opengis.net/kml/2.2">\s<Document>\s<Info>Generated by https://geotraceroute.com</Info>%%gs; $line =~ s%<name>.+</name>%%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