Created
August 25, 2025 19:25
-
-
Save fahadysf/5c3323333d0ad7ef1b52d6f85c5ea635 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
dnsserver=“your-dns-server.ns.cloudflare.com" | |
host="your-record-name" | |
domain_name=“yourdomain.com” | |
cf_user_email="[email protected]" | |
cf_api_key=“—get-your-own-api-key--“ | |
cf_zone_id="—get-your-own-zone-id—“” | |
cf_record_id=“check-your-own-record-id” | |
dnsrecord=$host.$domain_name | |
# Get the current external IP address | |
current_ip=`curl -s -X GET https://checkip.amazonaws.com` | |
datestr=`date` | |
## NameChaep FreeDNS Dynamic Update URL | |
## keep these private | |
UPDATE_URL="https://api.cloudflare.com/client/v4/zones/$cf_zone_id/dns_records/$cf_record_id" | |
echo "[$datestr] Current IP is $current_ip" | |
dnsresult="[$datestr] `host $dnsrecord $dnsserver | grep 'has address'`" | |
if echo $dnsresult | grep "$current_ip"; then | |
echo "[$datestr] $dnsrecord is currently set to $current_ip; no changes needed" | |
exit 0 | |
fi | |
#curl -X GET "https://api.cloudflare.com/client/v4/zones/41f2909777d668272873c17b3ae753c0/dns_records/" \ | |
# -H "X-Auth-Email: [email protected]" \ | |
# -H "X-Auth-Key: 9c3c329c9b2fadb40ffc3f2f2872efdd78633" \ | |
# -H "Content-Type: application/json" | |
#curl -X PUT "https://api.cloudflare.com/client/v4/zones/41f2909777d668272873c17b3ae753c0/dns_records/372e67954025e0ba6aaa6d586b9e0b59" \ | |
# -H "X-Auth-Email: [email protected]" \ | |
# -H "X-Auth-Key: 9c3c329c9b2fadb40ffc3f2f2872efdd78633" \ | |
# -H "Content-Type: application/json" \ | |
# --data '{"type":"A","name":"h","content":"127.0.0.1","ttl":3600,"proxied":false}' | |
# if here, the dns record needs updating | |
result=`curl -s -X PUT $UPDATE_URL -H "X-Auth-Email: $cf_user_email" -H "X-Auth-Key: $cf_api_key" -H "Content-Type: application/json" --data "{\"type\": \"A\", \"name\":\"h\", \"content\":\"$current_ip\", \"ttl\":180, \"proxied\":false}"` | |
echo "[$datestr] Update Result: $result" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment