Skip to content

Instantly share code, notes, and snippets.

@clarencetw
Created January 17, 2025 10:21
Show Gist options
  • Save clarencetw/be76a071bf3fd696fffeb6ec8ce9a62a to your computer and use it in GitHub Desktop.
Save clarencetw/be76a071bf3fd696fffeb6ec8ce9a62a to your computer and use it in GitHub Desktop.
DuckDNS Dynamic DNS Update Script
# DuckDNS Dynamic DNS Update Script
# Add this script to scheduler
# Configuration ---------------------------------------------------------------------
#
# Author: Clarence
# Website: https://clarence.tw
#
#------------------------------------------------------------------------------------
:local TOKEN "PUT-YOUR-DUCKDNS-TOKEN-HERE"
:local DOMAIN "PUT-YOUR-SUBDOMAIN-HERE"
:local WANIF "pppoe-out1"
#------------------------------------------------------------------------------------
:global IP4NEW
:global IP4CUR
:local url "https://www.duckdns.org/update\?domains=$DOMAIN&token=$TOKEN&ip="
:if ([/interface get $WANIF value-name=running]) do={
# Get the current public IP
:local currentIP [/ip address get [/ip address find interface=$WANIF] address];
:set IP4NEW [:pick $currentIP 0 [:find $currentIP "/"]]; # Remove CIDR suffix
# Check if IP has changed
:if ($IP4NEW != $IP4CUR) do={
:log info "DuckDNS-DDNS: Public IP changed to $IP4NEW, updating"
:local fullUrl "$url$IP4NEW"
:local response
:do {
:set response ([/tool fetch url=$fullUrl mode=https output=user as-value]->"data")
} on-error={
:log error "DuckDNS-DDNS: Failed to update IP address"
:error "DuckDNS-DDNS: Script aborted"
}
:set IP4CUR $IP4NEW
:log info "DuckDNS-DDNS: Host $DOMAIN updated with IP $IP4CUR"
} else={
:log info "DuckDNS-DDNS: Previous IP $IP4NEW not changed, quitting"
}
} else={
:log info "DuckDNS-DDNS: $WANIF is not currently running, quitting"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment