pyping
is a simple python script to report lost packets of an internet connection in CSV format. If the output is redirected to a CSV file, Excel Pivot Charts can later be used to analyze data.
There are no command line parameters. The target ping address must be edited in the source code (default target IP is Google DNS - 8.8.8.8).
Only lost packets and packets with a response time over 2.5 times the average are logged.
-
A PC or device running Linux (it may work on Windows but it was not tested). The commands below were tested on Raspberry Pi OS
-
Install or update
python3
sudo apt install python3
- Install or update
pip3
sudo apt install python3-pip
- Install python library
icmplib
sudo pip3 install icmplib
- Edit
pyping.py
and put the target ping address in the variablegblPingTarget
(...)
gblPingTarget = "8.8.8.8"
(...)
-
sudo python3 -u ./pyping.py > outputfile.csv" &
-
sudo python3 -u ./pyping.py > "$(pwd -P)/$(date +"%Y%m%d-%H%M").csv" &
Only lost packets and packets with a response time over 2.5 times the average events are logged.
-
timestamp: timestamp of the logged event in the format yyyy-dd-mm hh:mm:ss
-
address: ping target IP address (as configured in the variable
gblPingTarget
) -
totalSentPackets: total number of sent packets
-
totalLostPackets: total number of lost packets
-
seqLostPackets: number of lost packets in a row
-
totalPctLost: total percent of lost packets
-
avgResponseTime: average response time in milliseconds
-
lastResponseTime: response time of last received packet before the event in milliseconds
-
maxResponseTime: maximum response time in milliseconds
-
totalHighResponseTime: total number of packets with the response time above 2.5 times the average response time
-
totalPctAboveAvg: total percent of packets with a response time above 2.5 times the average
timestamp,address,totalSentPackets,totalLostPackets,seqLostPackets,totalPctLost,avgResponseTime,lastResponseTime,maxResponseTime,totalHighResponseTime,totalPctAboveAvg
2021-06-11 08:58:15,8.8.8.8,1381,1,1,0.07,11.5,12.2,35.5,0,0.00
2021-06-11 08:58:35,8.8.8.8,1399,2,1,0.14,11.5,14.2,35.5,0,0.00
2021-06-11 08:59:22,8.8.8.8,1443,3,1,0.21,11.5,11.3,35.5,0,0.00
2021-06-11 08:59:31,8.8.8.8,1450,4,1,0.28,11.5,15.9,35.5,0,0.00
2021-06-11 08:59:45,8.8.8.8,1460,6,2,0.41,11.5,21.7,35.5,0,0.00
2021-06-11 08:59:50,8.8.8.8,1463,7,1,0.48,11.5,17.0,35.5,0,0.00
2021-06-11 08:59:58,8.8.8.8,1469,8,1,0.54,11.5,12.8,35.5,0,0.00
2021-06-11 09:00:03,8.8.8.8,1474,8,0,0.54,11.7,250.6,250.6,1,0.07
2021-06-11 09:00:19,8.8.8.8,1488,9,1,0.60,11.7,12.5,250.6,1,0.07
2021-06-11 09:02:36,8.8.8.8,1621,10,1,0.62,11.7,15.7,250.6,1,0.06
(...)
The output from this script can be redirected to a CSV file and opened in Excel, for example. Excel Pivot Charts is a good tool that can be used to group data and to perform some analysis.
A sample Excel file is available in this repository.
Below is an example of this analysis grouping by day:
And a specific day can be expanded to group lost packets per hour: