aboutsummaryrefslogtreecommitdiffstats
path: root/har2kml
blob: 174a1e818ed818c63b3473287033b6995fbbc96f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/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
}

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

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;'