Created
July 30, 2021 15:37
-
-
Save OrvilleQ/93d029015f76ac125f32972f5b77845e to your computer and use it in GitHub Desktop.
Simple Cloudflare DDNS Shell Script
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
#!/bin/sh | |
# | |
# set -x | |
DOMAIN_NAME="<Domain name>" | |
IP_RECORD=`nslookup -type=a $DOMAIN_NAME | tail -n+4 | grep Address | sed -e '/^$/d' -e 's/Address: //g'` | |
IP_CURRENT=`curl -s ip.sb` | |
ZONE_IDENTIFIER= | |
DNS_IDENTIFIER= | |
API_TOKEN= | |
if [ $IP_RECORD != $IP_CURRENT ]; then | |
echo -e "Change DNS record to ${IP_CURRENT}." | |
curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/${ZONE_IDENTIFIER}/dns_records/${DNS_IDENTIFIER}" \ | |
-H "Authorization: Bearer ${API_TOKEN}" \ | |
-H "Content-Type: application/json" \ | |
--data "{\"type\":\"A\",\"name\":\"${DOMAIN_NAME}\",\"content\":\"${IP_CURRENT}\",\"ttl\":1,\"proxied\":false}" | |
else | |
echo -e "Everything is under control, bro." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment