sane-ip-check: set exit code based on if we get IP or not

This commit is contained in:
Colin 2023-02-21 11:17:54 +00:00
parent b048b47d54
commit 82d3e9686d
2 changed files with 9 additions and 5 deletions

View File

@ -1,3 +1,4 @@
#!/usr/bin/env bash
curl https://ipinfo.io/ip
echo
ip=$(curl --silent https://ipinfo.io/ip)
echo "$ip" | grep -P " *^\d+\.\d+\.\d+\.\d+ *$"
exit $?

View File

@ -3,13 +3,16 @@
# requires creds
passwd=$(sudo cat /run/secrets/router_passwd)
cookie=$(mktemp)
curlflags="curl --silent --insecure --cookie-jar $cookie --connect-timeout 5"
# authenticate
curl -s --insecure --cookie-jar $cookie \
curl $curlflags \
--data "username=admin&password=$passwd" \
https://192.168.0.1
# query the WAN IP
curl -s --insecure --cookie $cookie \
ip=$(curl $curlflags \
-H "X-Requested-With: XMLHttpRequest" \
"https://192.168.0.1/cgi/cgi_action?Action=GetConnectionStatus" \
| jq -r .wan_status.ipaddr
| jq -r .wan_status.ipaddr)
echo "$ip" | grep -P " *^\d+\.\d+\.\d+\.\d+ *$"
exit $?