Skip to content

Instantly share code, notes, and snippets.

@klustic
Last active July 30, 2019 17:59
Show Gist options
  • Save klustic/e91979de419686099261449ff3841f97 to your computer and use it in GitHub Desktop.
Save klustic/e91979de419686099261449ff3841f97 to your computer and use it in GitHub Desktop.
Traceroute for Linux hosts without traceroute/tracepath available
# To use this Bash function:
# [user]$ source tracert.sh
# [user]$ tracert
# Tracing to 8.8.8.8...
# 1 250.50.224.1
# ...
# [user]$ tracert 1.1.1.1
# Tracing to 1.1.1.1...
# 1 250.50.224.1
# ...
tracert ()
{
HOST=${1:-8.8.8.8};
echo Tracing to $HOST...;
for i in $(seq 1 35);
do
data=$(ping -n -w2 -c 1 -t $i 8.8.8.8 2>&1);
if [ $? -eq 0 ]; then
echo -e "$i\t$HOST";
break;
fi;
echo -e "$i\t$(echo $data | egrep -o "From [^ ]+" | cut -d" " -f2)";
sleep 1;
i=$[i+1];
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment