From f2cac45139b1ee46416d032eeb44596419e651b7 Mon Sep 17 00:00:00 2001
From: Salt <rehashedsalt@cock.li>
Date: Sun, 28 Feb 2021 01:11:48 -0600
Subject: [PATCH] Add basic packetloss script

---
 packetloss | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100755 packetloss

diff --git a/packetloss b/packetloss
new file mode 100755
index 0000000..c139fcc
--- /dev/null
+++ b/packetloss
@@ -0,0 +1,34 @@
+#! /bin/bash
+
+declare -i samples=100
+declare -a servers=('1.1.1.1' '8.8.8.8')
+declare -i highestloss=0
+
+declare -i alltimehighest=0
+declare -i alltimelowest=0
+declare -i iterations=1
+
+while :; do
+	highestloss=0
+	for server in "${servers[@]}"; do
+		stats="$(ping "$server" -c "$samples" | tail -n 2 | head -n 1)"
+		losspercent="$(echo "$stats" | cut -f6 -d ' ')"
+		loss="${losspercent%\%}"
+		[ -z "$loss" ] && continue
+		if (( loss > highestloss )); then
+			highestloss="$loss"
+		fi
+	done
+	color="\e[34m"
+	if (( highestloss > 0 )); then
+		color="\e[31m"
+	fi
+	printf "\\rCurrent loss: $color%-3.3s\e[0m - \e[33m%-4.4s \e[34m%-4.4s \e[0m%-4.4s" \
+		"$highestloss" \
+		"$alltimehighest" \
+		"$alltimelowest" \
+		"$iterations"
+	iterations="$(( iterations + 1 ))"
+	sleep 1
+done
+