From 7c33de02702e8035cd89a3a896e60be720ebad5c Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Sun, 1 Jan 2023 13:49:48 -0600 Subject: [PATCH] Create get-wanip.sh --- get-wanip.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 get-wanip.sh diff --git a/get-wanip.sh b/get-wanip.sh new file mode 100755 index 0000000..3f6a9e9 --- /dev/null +++ b/get-wanip.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +wanip="$(dig +short myip.opendns.com @resolver1.opendns.com)" >/dev/null 2>&1 +if [ "${wanip}" == "" ]; then + wanip="$(host myip.opendns.com resolver1.opendns.com)" >/dev/null 2>&1 + if [ "${wanip}" == "" ]; then + wanip="$(curl https://ipinfo.io/ip)" >/dev/null 2>&1 + if [ "${wanip}" == "" ]; then + wanip="$(wget -qO- https://ipecho.net/plain ; echo)" >/dev/null 2>&1 + else + echo "WAN IP could not be found" + exit 1 + fi + fi +fi + +echo "WAN IP: ${wanip}" + +exit 0 \ No newline at end of file