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

20 lines
489 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/'
}
function get_ip_addresses() {
ip -4 -json address | jq -r --arg ifregex "${1:-lo}" '
map(select(.ifname | test($ifregex) | not) |
.ifname + ":" + (.addr_info | map(.local) | join(","))) |
join(" ")
'
}
echo -n "<txt>$(get_ip_addresses "$1") $(doPing 8.8.8.8 G)</txt>"