Last active
November 24, 2020 11:07
-
-
Save kevinoconnor7/4036347 to your computer and use it in GitHub Desktop.
CloudFlare Dynamic DNS
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 | |
WAN_IP=`curl ifconfig.io/ip` | |
OLD_WAN_IP=`cat /var/CURRENT_WAN_IP.txt` | |
if [ "$WAN_IP" = "$OLD_WAN_IP" ] | |
then | |
echo "IP Unchanged" | |
else | |
curl https://www.cloudflare.com/api_json.html \ | |
-d 'a=rec_edit' \ | |
-d 'tkn=8afbe6dea02407989af4dd4c97bb6e25' \ | |
-d 'email=sample@example.com' \ | |
-d 'z=example.com' \ | |
-d 'id=9001' \ | |
-d 'type=A' \ | |
-d 'name=sub' \ | |
-d 'ttl=1' \ | |
-d "content=$WAN_IP" | |
echo $WAN_IP > /var/CURRENT_WAN_IP.txt | |
fi |
Thanks.
When ifconfig.io/ip will not be available, the script will go wild. You need to make sure that ifconfig.io/ip returns a proper IP address (maybe by using a regex), and only then update check if is new and proceed by updating the new IP.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! This is working for me!