Create get-wanip.sh

This commit is contained in:
2023-01-01 13:49:48 -06:00
parent 973e682abd
commit 7c33de0270

19
get-wanip.sh Executable file
View File

@@ -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