Added Njalla OpenWRT DDNS script

This commit is contained in:
Logan G 2024-02-17 02:19:57 -07:00
parent 7f77a96875
commit 2e92dbeb72
Signed by: logan
GPG key ID: E328528C921E7A7A

43
openwrt-njalla-ddns.sh Normal file
View 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