#!/bin/bash
function doPing () {
# $1 = target
# $2 = letter
ping -c1 -W1 "$1" | \
(grep "bytes from" || echo "$2:Down") | \
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 "${ip}$(doPing 8.8.8.8 G)"