-
-
Save eliroca/90166c0c4a3bf75f229496fd48c6a0aa 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 sh | |
# Get the Zone ID from: https://www.cloudflare.com/a/overview/<your-domain> | |
DNS_ZONE=*** | |
# Get the existing identifier for DNS entry: | |
# https://api.cloudflare.com/#dns-records-for-a-zone-list-dns-records | |
IDENTIFIER=*** | |
# Get these from: https://www.cloudflare.com/a/account/my-account | |
AUTH_EMAIL=*** | |
AUTH_KEY=*** | |
# Desired domain name | |
DOMAIN_NAME="***" | |
# Get previous IP address | |
_PREV_IP_FILE="/tmp/public-ip.txt" | |
_PREV_IP=$(cat $_PREV_IP_FILE) | |
# Curl fritzbox public IP | |
_IP=$(curl "http://192.168.1.1:49000/igdupnp/control/WANIPConn1" \ | |
-H "Content-Type: text/xml; charset="utf-8"" \ | |
-H "SoapAction:urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress" \ | |
-d "<?xml version='1.0' encoding='utf-8'?> <s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'> <s:Body> <u:GetExternalIPAddress xmlns:u='urn:schemas-upnp-org:service:WANIPConnection:1' /> </s:Body> </s:Envelope>" \ | |
-s | grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>') | |
#_IP=$(curl --silent https://api.ipify.org) | |
echo $_IP | |
# If new/previous IPs match, no need for an update. | |
if [ "$_IP" = "$_PREV_IP" ]; then | |
exit 0 | |
fi | |
echo $_IP | |
_UPDATE=$(cat <<EOF | |
{ "type": "A", | |
"name": "$DOMAIN_NAME", | |
"content": "$_IP", | |
"ttl": 120, | |
"proxied": true } | |
EOF | |
) | |
curl "https://api.cloudflare.com/client/v4/zones/$DNS_ZONE/dns_records/$IDENTIFIER" \ | |
--silent \ | |
-X PUT \ | |
-H "Content-Type: application/json" \ | |
-H "X-Auth-Email: $AUTH_EMAIL" \ | |
-H "X-Auth-Key: $AUTH_KEY" \ | |
-d "$_UPDATE" > /tmp/cloudflare-ddns-update.json && \ | |
echo $_IP > $_PREV_IP_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment