Skip to content

Instantly share code, notes, and snippets.

@paulsmith paulsmith/README.md
Last active Aug 29, 2015

Embed
What would you like to do?
Latency and packet loss report

If you are experiencing poor or degrading home network performance, it's good to come armed with evidence when talking with your friendly neighborhood ISP.

Usage:

From your cable or DSL modem, find out the gateway, aka your ISP's router between you and them. Usually you can just run netstat -rn and the entry next to destination==0.0.0.0 is the gateway. (Be sure to be plugged directly into your modem, not going through your WiFi router, or you'll just be getting the gateway of your internal private network, which will be the WiFi router itself.) Armed with that IP address, log a few hours worth of ping(8) to a file, and then run ping_report.sh on it.

$ ping -D <gwipaddress> | tee ping.log
# wait a few hours
<ctrl-c>
$ ./ping_report.sh ping.log
mean        95th        99th         %packetloss
121.271164  757.000000  2070.000000  8.00
#!/bin/bash
set -u -e
file=$1
(echo "mean 95th 99th %packetloss" | col
cat $file | awk '/icmp_seq/ {print $8}' | cut -f2 -d= | sort -n | \
awk '{s[NR-1]=$1; sum+=$1} END {printf("%f %f %f ", sum/NR, s[int(NR*0.95-0.5)], s[int(NR*0.99-0.5)])}'; \
echo "scale=2; 100*(1-`wc -l $file | cut -f1 -d' '`/`tail -1 $file | awk '{print $6}' | cut -f2 -d=`)" | bc) | \
column -t
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.