sane-ip-check: set exit code based on if we get IP or not
This commit is contained in:
parent
b048b47d54
commit
82d3e9686d
|
@ -1,3 +1,4 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
curl https://ipinfo.io/ip
|
ip=$(curl --silent https://ipinfo.io/ip)
|
||||||
echo
|
echo "$ip" | grep -P " *^\d+\.\d+\.\d+\.\d+ *$"
|
||||||
|
exit $?
|
||||||
|
|
|
@ -3,13 +3,16 @@
|
||||||
# requires creds
|
# requires creds
|
||||||
passwd=$(sudo cat /run/secrets/router_passwd)
|
passwd=$(sudo cat /run/secrets/router_passwd)
|
||||||
cookie=$(mktemp)
|
cookie=$(mktemp)
|
||||||
|
curlflags="curl --silent --insecure --cookie-jar $cookie --connect-timeout 5"
|
||||||
|
|
||||||
# authenticate
|
# authenticate
|
||||||
curl -s --insecure --cookie-jar $cookie \
|
curl $curlflags \
|
||||||
--data "username=admin&password=$passwd" \
|
--data "username=admin&password=$passwd" \
|
||||||
https://192.168.0.1
|
https://192.168.0.1
|
||||||
# query the WAN IP
|
# query the WAN IP
|
||||||
curl -s --insecure --cookie $cookie \
|
ip=$(curl $curlflags \
|
||||||
-H "X-Requested-With: XMLHttpRequest" \
|
-H "X-Requested-With: XMLHttpRequest" \
|
||||||
"https://192.168.0.1/cgi/cgi_action?Action=GetConnectionStatus" \
|
"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 $?
|
||||||
|
|
Loading…
Reference in New Issue
Block a user