Skip to content

Instantly share code, notes, and snippets.

@nishanths
Created March 23, 2020 07:44
Show Gist options
  • Save nishanths/e331a91179fd90e8dc17b721d6a7b264 to your computer and use it in GitHub Desktop.
Save nishanths/e331a91179fd90e8dc17b721d6a7b264 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
# Updates the freedns.afraid.org DNS record for a domain, if the domain's
# resolved IP does not match the external IP of the machine running this program.
usage() {
echo "usage: afraiddns.sh <domain>"
exit 1
}
DOMAIN=$1
[ -z $DOMAIN ] && usage
EXISTING=$(nslookup $DOMAIN | grep "Address" | tail -n 1 | sed 's/[^0-9.]//g')
NEW=$(dig +short myip.opendns.com @resolver1.opendns.com)
[ $NEW != $EXISTING ] && curl "http://freedns.afraid.org/dynamic/update.php?"$AFRAID_DNS_API_KEY
echo date=$(date) existing=$EXISTING new=$NEW
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment