Skip to content

Instantly share code, notes, and snippets.

@sjaek
Created May 1, 2018 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjaek/02d52b3e7cf14be6a64f947ff255329d to your computer and use it in GitHub Desktop.
Save sjaek/02d52b3e7cf14be6a64f947ff255329d to your computer and use it in GitHub Desktop.
nsupdate-info
#! /usr/bin/env bash
# Update script for nsupdate.info dynamic dns
DOMAIN=$1
TOKEN=$2
if [ -z "$DOMAIN" -o -z "$TOKEN" ] ; then
echo "Usage: "`basename $0`" <nsupdate.info domain> <token>"
exit 1
fi
CURRENT_DNS_IP=`dig +noall +answer @ns1.nerdpol.io. A $DOMAIN | sed -E 's/.*\s+IN\s+A\s+(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))/\1/g'`
CURRENT_EXTERNAL_IP=`curl -s https://ipv4.nsupdate.info/myip`
if [ "$CURRENT_DNS_IP" != "$CURRENT_EXTERNAL_IP" ] ; then
echo
echo "Changing IP from $CURRENT_DNS_IP to $CURRENT_EXTERNAL_IP"
#curl -u "${DOMAIN}:${TOKEN}" https://ipv4.nsupdate.info/nic/update
if [ "$?" != "0" ] ; then
echo "Error updating IP"
exit 1
fi
else
echo "DNS Up-to-date"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment