xfce4-panel/.config/xfce4/panel/scripts/netstatus.sh

23 lines
479 B
Bash
Executable File

#!/bin/bash
function doPing () {
# $1 = target
# $2 = letter
ping -c1 -W1 "$1" | \
(grep "bytes from" || echo "<span fgcolor=\"red\">$2:Down</span>") | \
sed 's/.*time=\([0-9\.]*\).*/'"$2"':\1ms/'
}
if [[ "$@" -ne "" ]]
then
interfaces=$(ip -4 -o a | grep "$@")
else
interfaces=$(ip -4 -o a)
fi
ip=$(echo "$interfaces" | \
sed 's/^[0-9]*: \([^ ]*\) inet \([0-9.]*\).*/\1:\2/g' | \
grep -v lo | \
tr '\n' ' ')
echo -n "<txt>${ip}$(doPing 8.8.8.8 G)</txt>"