Skip to content

Cloudflare DDNS PowerShell Script for Windows OS. Choose any source IP address to update external or internal (WAN/LAN). Cloudflare's options proxy and TTL configurable via the parameters.

Notifications You must be signed in to change notification settings

fire1ce/DDNS-Cloudflare-PowerShell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DDNS Cloudflare PowerShell Script

contributions welcome MIT license

  • DDNS Cloudflare PowerShell script for Windows.
  • Choose any source IP address to update external or internal (WAN/LAN).
  • For multiple LAN interfaces like Wifi, Docker Networks and Bridges the script will automatically detect the primary Interface by priority.
  • Cloudflare's options for proxy and TTL configurable via the parameters.
  • Optional Telegram or Discord Notifications

Requirements

  • Cloudflare api-token with ZONE-DNS-EDIT Permissions
  • DNS Record must be pre created (api-token should only edit dns records)
  • Enabled running unsigned PowerShell

Creating Cloudflare API Token

To create a CloudFlare API token for your DNS zone go to https://dash.cloudflare.com/profile/api-tokens and follow these steps:

  1. Click Create Token
  2. Select Create Custom Token
  3. Provide the token a name, for example, example.com-dns-zone-readonly
  4. Grant the token the following permissions:
    • Zone - DNS - Edit
  5. Set the zone resources to:
    • Include - Specific Zone - example.com
  6. Complete the wizard and use the generated token at the CLOUDFLARE_API_TOKEN variable for the container

Installation

Download the DDNS-Cloudflare-PowerShell zip file & Unzip, rename the folder to DDNS-Cloudflare-PowerShell place in a directory of your choosing

Config Parameters

Update the config parameters inside the update-cloudflare-dns_conf.ps1 by editing accordingly. See below for examples.

Option Example Description
what_ip internal Which IP should be used for the record: internal/external
dns_record ddns.example.com DNS A record which will be updated
cloudflare_zone_api_token ChangeMe Cloudflare API Token KEEP IT PRIVATE!!!!
zoneid ChangeMe Cloudflare's Zone ID
proxied false Use Cloudflare proxy on dns record true/false
ttl 120 120-7200 in seconds or 1 for Auto

Optional Notifications Parameters for Telegram

Option Example Description
notify_me_telegram yes Use Telegram notifications yes/no
telegram_chat_id ChangeMe Chat ID of the bot
telegram_bot_API_Token ChangeMe Telegram's Bot API Token

Optional Notification Parameters for Discord

Option Example Description
notify_me_discord yes Use Discord notifications yes/no
discord_webhook_URL http://WebhookURL.com/asd/ Webhook URL from your Discord server settings

To generate a webhook URL, follow the official Discord instructions.

Running The Script

Open cmd/powershell

Example:

powershell.exe -ExecutionPolicy Bypass -File C:\DDNS-Cloudflare-PowerShell\update-cloudflare-dns.ps1

Automation With Windows Task Scheduler

Example: Run at boot with 1 min delay and repeat every 1 min

  • Open Task Scheduler
  • Action -> Crate Task
  • General Menu
    • Name: update-cloudflare-dns
    • Run whether user is logged on or not
  • Trigger
    • New...
    • Begin the task: At startup
    • Delay task for: 1 minute
    • Repeat task every: 1 minute
    • for duration of: indefinitely
    • Enabled
  • Actions
    • New...
    • Action: Start a Program
    • Program/script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    • Add arguments: -ExecutionPolicy Bypass -File C:\DDNS-Cloudflare-PowerShell\update-cloudflare-dns.ps1
    • ok
    • Enter your user's password when prompted
  • Conditions
    • Power: Uncheck - [x] Start the task only if the computer is on AC power

Logs

This Script will create a log file with only the last run information
Log file will be located as same directory as update-cloudflare-dns.ps1

Log file name:

update-cloudflare-dns.log

Limitations

  • Does not support IPv6

License

MIT License

Copyright© 3os.org @2020

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.