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
|
||||
curl https://ipinfo.io/ip
|
||||
echo
|
||||
ip=$(curl --silent https://ipinfo.io/ip)
|
||||
echo "$ip" | grep -P " *^\d+\.\d+\.\d+\.\d+ *$"
|
||||
exit $?
|
||||
|
|
|
@ -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 $?
|
||||
|
|
Loading…
Reference in New Issue
Block a user