Skip to content

Instantly share code, notes, and snippets.

@melnik13 melnik13/pingtrace.sh
Last active Sep 29, 2015

Embed
What would you like to do?
When you can't install the mtr utility, but need to determine on which hop your datagrams are being lost
#/bin/bash
HST="8.8.8.8"
CNT="100"
DIR="$(mktemp -d /tmp/ping_XXXXXXXX)"
echo "Results will be stored to the ${DIR} directory"
for HOP in $(traceroute -n "${HST}" | sed -nr 's/^[[:space:]]*([[:digit:]]+)[[:space:]]+([[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3})[[:space:]]+.*$/\1:\2/gp'); do
IFS_OLD="${IFS}"; IFS=":"; read -a ARR <<< "${HOP}"; IFS="${IFS_OLD}"
ping -c "${CNT}" ${ARR[1]}" > "${DIR}/pingtrace_${ARR[0]}_${ARR[1]}" &
done
echo -n "Waiting for ${CNT} packets to be sent..."; sleep "$((CNT+3))"; echo "OK!"
grep "transmitted" "${DIR}"/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.