aboutsummaryrefslogtreecommitdiffstats
path: root/har2kml
blob: b95cd02ef277305ed73a7ee771377f4b28c6370d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/sh
#
# Use geotraceroute to fetch traceroutes to all hosts used to view a web page and print KML
# output for all traces.

if [ "$1" ]; then
    har="$1"
else
    har=har-data/https\:%%www.politi.no.har
fi

har2hosts() {
    jq -r '.log | .entries | map(.request) | map(.url) | join("\n")' < $har |
        cut -d/ -f3 | sort -u
}

for h in $(har2hosts) ; do
    kml="$h.kml"
    curl -s "https://www.geotraceroute.com/petter.php?host=$h" > "$kml"
    kmls="$kmls $kml"
done

cat $kmls | 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;'