Last active
February 26, 2020 18:39
-
-
Save mauron85/bd11f1b37e0f99f1d247187e95199fad to your computer and use it in GitHub Desktop.
Easy update DNS via Cloudfare API
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
# Script from: | |
# https://postapocalyptech.com/posts/use_cloudflare_ddns/ | |
# adjusted for OpenWrt's ash | |
# Running curl command and getting your IP address using akamai's service | |
# Store it in IPADDRNOW variable | |
IPADDRNOW=$(curl -s http://whatismyip.akamai.com/); \ | |
# Using cat to read stored IP address and then putting it in STOREDIP variable | |
STOREDIP=`cat /tmp/ipaddrnow.txt 2>/dev/null`;\ | |
# Comparing the stored IP address to the curl result - if it differs, | |
# we'll use Curl to send the new IP address through Cloudflare's API | |
# You'll need to fill in your home folder for the ipaddrnow.txt file, | |
# your email address, your key, zone_ID, DNS_ID, and (domain) Name | |
if [ "$IPADDRNOW" != "$STOREDIP" ]; \ | |
then | |
echo $IPADDRNOW > /tmp/ipaddrnow.txt; \ | |
EMAIL="[email protected]"; \ | |
KEY="abcdefgh"; \ | |
ZONE_ID="abcdefgh"; \ | |
DNS_ID="abcdefgh"; \ | |
TYPE="A"; \ | |
NAME="gw.penzion-hello.sk"; \ | |
PROXIED="false"; \ | |
TTL="120";\ | |
curl -X PUT "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$DNS_ID" \ | |
-H "X-Auth-Email: $EMAIL" \ | |
-H "X-Auth-Key: $KEY" \ | |
-H "Content-Type: application/json" \ | |
--data '{"type":"'"$TYPE"'","name":"'"$NAME"'","content":"'"$IPADDRNOW"'","proxied":'"$PROXIED"',"ttl":'"$TTL"'}' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment