Last active
February 17, 2022 14:23
-
-
Save ShortyDev/a6fc108087e4d408d54e4964808e990c to your computer and use it in GitHub Desktop.
Script to update your IP on a Cloudflare DNS entry
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
if [ ! -e address.txt ]; then | |
touch address.txt | |
echo "nothing" > address.txt | |
fi | |
read storedAddress < address.txt | |
dnsName=%%_CLOUDFLARE_DNS_NAME_%% | |
zoneId=%%_CLOUDFLARE_ZONE_ID_%% | |
dnsId=%%_CLOUDFLARE_DNS_ID_%% | |
token=%%_CLOUDFLARE_API_TOKEN_%% | |
apiUrl=https://api.cloudflare.com/client/v4/zones/$zoneId/dns_records/$dnsId | |
fetchedAddress=$(curl -s ifconfig.me/ip) | |
if [ $storedAddress != $fetchedAddress ]; then | |
echo $fetchedAddress > address.txt | |
echo "Changing IP..." | |
curl -X PUT $apiUrl -H "Content-Type: application/json" -H "Authorization: Bearer $token" --data-binary "{\"type\":\"A\",\"name\":\"$dnsName\",\"content\":\"$fetchedAddress\",\"ttl\":1,\"proxied\":false}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment