Sometimes you need to detect which host loses IP-packets being sent by you. It’s good when you can use the mtr utility, but what to do if you can’t install it?
Here’s a short and very simple script that could help you with that.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#/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}"/* |
It traces the route to the destination and then run a bunch of simultaneous ping commands to all hosts found.
Also published to Gist.