Added Njalla OpenWRT DDNS script
This commit is contained in:
parent
7f77a96875
commit
2e92dbeb72
1 changed files with 43 additions and 0 deletions
43
openwrt-njalla-ddns.sh
Normal file
43
openwrt-njalla-ddns.sh
Normal file
|
@ -0,0 +1,43 @@
|
|||
#!/bin/ash
|
||||
|
||||
IP_TEMPFILE=/tmp/wanip
|
||||
NJALLA_SUBDOMAIN="thing.com"
|
||||
NJALLA_KEY="1234"
|
||||
|
||||
|
||||
# Gets the current WAN interface and IP(s)
|
||||
. /lib/functions/network.sh
|
||||
network_flush_cache
|
||||
network_find_wan NET_IF
|
||||
network_find_wan6 NET_IF6
|
||||
network_get_ipaddr NET_ADDR "${NET_IF}"
|
||||
network_get_ipaddr6 NET_ADDR6 "${NET_IF6}"
|
||||
|
||||
if [ "$1" = "--query" ]; then
|
||||
echo "Querying IP from DNS server"
|
||||
NET_ADDR_OLD="$(nslookup -type=a ${NJALLA_SUBDOMAIN} | awk '/^Address: / { print $2 }')"
|
||||
NET_ADDR6_OLD="$(nslookup -type=aaaa ${NJALLA_SUBDOMAIN} | awk '/^Address: / { print $2 }')"
|
||||
else
|
||||
if [ -f ${IP_TEMPFILE} ]; then
|
||||
. ${IP_TEMPFILE}
|
||||
else
|
||||
NET_ADDR_OLD="$(nslookup -type=a ${NJALLA_SUBDOMAIN} | awk '/^Address: / { print $2 }')"
|
||||
NET_ADDR6_OLD="$(nslookup -type=aaaa ${NJALLA_SUBDOMAIN} | awk '/^Address: / { print $2 }')"
|
||||
echo "NET_ADDR_OLD=${NET_ADDR}" > $IP_TEMPFILE
|
||||
echo "NET_ADDR6_OLD=${NET_ADDR6}" >> $IP_TEMPFILE
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$NET_ADDR" != "$NET_ADDR_OLD" ] || [ "$NET_ADDR6" != "$NET_ADDR6_OLD" ] || [ "$1" = "--force" ]; then
|
||||
echo "IPv4: ${NET_ADDR_OLD} => ${NET_ADDR}"
|
||||
echo "IPv6: ${NET_ADDR6_OLD} => ${NET_ADDR6}"
|
||||
|
||||
wget -q -O /dev/null "https://njal.la/update/?h=${NJALLA_SUBDOMAIN}&k=${NJALLA_KEY}&a=${NET_ADDR}&aaaa=${NET_ADDR6}"
|
||||
STATUS=$?
|
||||
if [ $STATUS -ne 0 ]; then
|
||||
echo "Could not set DDNS IP! (${STATUS})"
|
||||
fi
|
||||
|
||||
echo "NET_ADDR_OLD=${NET_ADDR}" > $IP_TEMPFILE
|
||||
echo "NET_ADDR6_OLD=${NET_ADDR6}" >> $IP_TEMPFILE
|
||||
fi
|
Loading…
Reference in a new issue