Added generic Njalla DDNS script
This commit is contained in:
parent
c711ffc42c
commit
d03bf1f30c
1 changed files with 37 additions and 0 deletions
37
misc/generic-njalla-ddns.sh
Normal file
37
misc/generic-njalla-ddns.sh
Normal file
|
@ -0,0 +1,37 @@
|
|||
#!/bin/sh
|
||||
|
||||
IP_TEMPFILE=/tmp/wanip
|
||||
NJALLA_SUBDOMAIN="thing.com"
|
||||
NJALLA_KEY="1234"
|
||||
|
||||
# Gets the current WAN interface and IP(s)
|
||||
NET_ADDR=$(ip route get 9.9.9.9 | grep src | sed 's/.*src \(.* \)/\1/g' | cut -f1 -d ' ')
|
||||
NET_ADDR6=$(ip route get 2620:fe::fe | grep src | sed 's/.*src \(.* \)/\1/g' | cut -f1 -d ' ')
|
||||
|
||||
if [ "$1" = "--query" ] || [ ! -f ${IP_TEMPFILE} ]; 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 }')"
|
||||
|
||||
if [ ! -f ${IP_TEMPFILE} ]; then
|
||||
touch ${IP_TEMPFILE} || exit 1
|
||||
echo "NET_ADDR_OLD=${NET_ADDR_OLD}" > $IP_TEMPFILE
|
||||
echo "NET_ADDR6_OLD=${NET_ADDR6_OLD}" >> $IP_TEMPFILE
|
||||
fi
|
||||
else
|
||||
. ${IP_TEMPFILE}
|
||||
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