Skip to content

Instantly share code, notes, and snippets.

@venam
Last active April 1, 2025 07:55
Show Gist options
  • Save venam/13e00e5a3ceb9ca779be291170b53102 to your computer and use it in GitHub Desktop.
Save venam/13e00e5a3ceb9ca779be291170b53102 to your computer and use it in GitHub Desktop.
tracepath with geoloc
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 <destination>"
exit 1
fi
destination=$1
stdbuf -oL tracepath -n $destination | while read line; do
ip=$(echo $line | grep -oP '\d+\.\d+\.\d+\.\d+')
if [[ -n $ip ]]; then
curl -s "https://ipinfo.io/$ip/json" | jq -r --arg line "$line" '"\($line) - City: \(.city), Country: \(.country)"'
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment