From b4bc3b5585c7bfca391cf10a92a854ffe098501a Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Mon, 13 May 2019 10:53:49 +0300 Subject: [PATCH] local ips --- web/whatismyip | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/web/whatismyip b/web/whatismyip index 370cf43..c44c31c 100755 --- a/web/whatismyip +++ b/web/whatismyip @@ -4,14 +4,24 @@ function helpexit() { echo "Print your public internet IP address." echo "-n return as host name." + echo "-l display only local addresses." exit } +function locals_only() { + ip -4 -o addr | awk '!/^[0-9]*: ?lo|link\/ether/ {printf "%18s %s\n", $4, $2}' | sort -k 2 + exit $? +} for (( i=1; i<=$#; i++ )); do [[ "${!i}" = "--help" ]] && helpexit [[ "${!i}" = "-h" ]] && helpexit [[ "${!i}" = "-n" ]] && { NAME=1; continue; } + [[ "${!i}" = "-l" ]] && { LOCAL=1; continue; } done +if [[ "$LOCAL" -eq 1 ]]; then + locals_only +fi + which dig &> /dev/null || { echo Install apt dnsutils >&2 exit 1