Created
March 23, 2020 07:44
-
-
Save nishanths/e331a91179fd90e8dc17b721d6a7b264 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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