From 00baf0f20e11a68da0f2de8f29b890bacee9ef9f Mon Sep 17 00:00:00 2001 From: thek4n Date: Fri, 10 Jan 2025 22:00:08 +0300 Subject: [PATCH] myip command --- home/user/.local/bin/myip | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/home/user/.local/bin/myip b/home/user/.local/bin/myip index 69e7323..ef92d9c 100755 --- a/home/user/.local/bin/myip +++ b/home/user/.local/bin/myip @@ -2,11 +2,19 @@ TAB="$(printf -- '\t')" +readonly TAB + + +execute_and_format_result() { + cmd="${1}" + + ip="$(${cmd} 2>/dev/null)" + + printf "%s\t%s\n" "${ip}" "${cmd}" +} + { - printf "%s\t" "curl ipinfo.io/ip" - curl ipinfo.io/ip 2>/dev/null - echo - printf "%s\t" "dig +short myip.opendns.com @resolver1.opendns.com" - dig +short myip.opendns.com @resolver1.opendns.com 2>/dev/null + execute_and_format_result "curl ipinfo.io/ip" + execute_and_format_result "dig +short myip.opendns.com @resolver1.opendns.com" } | column -t -s "${TAB}"