Skip to content

Instantly share code, notes, and snippets.

@bebehei
Last active June 2, 2018 20:01
Show Gist options
  • Save bebehei/b8f8f5b38f7978990340f1c99a8636d8 to your computer and use it in GitHub Desktop.
Save bebehei/b8f8f5b38f7978990340f1c99a8636d8 to your computer and use it in GitHub Desktop.
nsupdate.info DDNS client
#!/bin/bash
set -euo pipefail
DNS_REC=<your record>
SEC=<secret>
INTERVAL=1200 # in seconds
DNS_MASTER="$(dig SOA +short "${DNS_REC}")"
unchanged4() {
local DNS_IP4 ASS_IP4
DNS_IP4="$(dig A +short "@${DNS_MASTER}" "${DNS_REC}")"
ASS_IP4="$(curl -s https://ipv4.nsupdate.info/myip)"
[ "${DNS_IP4}" == "${ASS_IP4}" ]
}
unchanged6() {
local DNS_IP6 ASS_IP6
DNS_IP6="$(dig AAAA +short "@${DNS_MASTER}" "${DNS_REC}")"
ASS_IP6="$(curl -s https://ipv6.nsupdate.info/myip)"
[ "${DNS_IP6}" == "${ASS_IP6}" ]
}
# Crawl nsupdate to update IP
update4(){
echo "Updating IPv4 address"
curl -s "https://${DNS_REC}:${SEC}@ipv4.nsupdate.info/nic/update"
}
update6(){
echo "Updating IPv6 address"
curl -s "https://${DNS_REC}:${SEC}@ipv6.nsupdate.info/nic/update"
}
while : ; do
unchanged4 || update4
unchanged6 || update6
sleep "${INTERVAL}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment