Skip to content

Instantly share code, notes, and snippets.

@elbosso
Created May 29, 2021 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elbosso/77f50ad31457d97ad8286e3d1f914198 to your computer and use it in GitHub Desktop.
Save elbosso/77f50ad31457d97ad8286e3d1f914198 to your computer and use it in GitHub Desktop.
A bash script for rendering the result of a traceroute call on a OpenStreetView Map. Its only parameter is the destination - for example `geolocationgeojson.sh iana.org` - uses https://gist.github.com/rajanski/4d2595c1fd4e35c19b4e1a02b4ed579f
#!/bin/bash
# prerequistes:
# * wget
# * traceroute
# * xdg-open
# with help from https://gist.github.com/rajanski/4d2595c1fd4e35c19b4e1a02b4ed579f
commaneeded=""
echo '{"type":"Feature","geometry":{"coordinates":[' >"$1_track.geojson"
traceroute $1 | tail -n +2 |grep "(" | uniq|cut -d '(' -f 2|rev|cut -d ')' -f 2|rev| while read line ; do
echo "=== $line ==="
if [ ! -f "/tmp/${line}" ]; then
#echo "retrieving $line"
wget "https://api.ipgeolocationapi.com/geolocate/$line" -P /tmp/
#else
#echo "/tmp/$line exists"
fi
lon=$(cat "/tmp/${line}" | jq .geo.longitude_dec| sed -e 's/^"//' -e 's/"$//')
lat=$(cat "/tmp/${line}" | jq .geo.latitude_dec| sed -e 's/^"//' -e 's/"$//')
if [ ! -z "$lon" ]; then
if [ ! -z "$lat" ]; then
#echo -e "${line}\t${lon}\t${lat}"
echo "#$commaneeded#"
if [ ! -z "$commaneeded" ]; then
echo ",[${lon},${lat}]" >>"$1_track.geojson"
else
echo "[${lon},${lat}]" >>"$1_track.geojson"
commaneeded="true"
fi
fi
fi
done
echo "],\"type\":\"LineString\"},\"properties\":{\"name\":\"traceroute ${1}\"}}" >>"$1_track.geojson"
if [ ! -f "/tmp/view_geojson.sh" ]; then
wget https://gist.githubusercontent.com/rajanski/4d2595c1fd4e35c19b4e1a02b4ed579f/raw/b0b291d5313015d552b456dbc2c6d59aabc821bc/view_geojson.sh -P /tmp/
sed -i 's/google-chrome/xdg-open/' /tmp/view_geojson.sh
fi
bash /tmp/view_geojson.sh -f "$1_track.geojson"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment