Skip to content

Instantly share code, notes, and snippets.

@darrena092
Last active April 1, 2024 09:35
Show Gist options
  • Save darrena092/1160b43d1266929b6a07663da88604e6 to your computer and use it in GitHub Desktop.
Save darrena092/1160b43d1266929b6a07663da88604e6 to your computer and use it in GitHub Desktop.
Mikrotik RouterOS DDNS update script for Namecheap domains
:global currentPublicIP
:local host "" # Add your subdomain here
:local domain "" # Add your domain here
:local password "" # Add your access token here
:local ddnsInterface "pppoe-out1"
:local newPublicIP [/ip address get [find interface="$ddnsInterface"] address]
:local unmaskedIP [:pick "$newPublicIP" 0 [:find "$newPublicIP" "/"]]
:local namecheapUpdateURL "https://dynamicdns.park-your-domain.com/update?host=$host&domain=$domain&password=$password&ip=$unmaskedIP"
:if ( $currentPublicIP = nil || ( $newPublicIP != $currentPublicIP ) ) do= {
:if ( $currentPublicIP = nil ) do= {
/log info "DDNS: Previous public IP not set. Updating DDNS to $newPublicIP."
} else={
/log info "DDNS: Updating record from $currentPublicIP to $newPublicIP"
}
:global currentPublicIP "$newPublicIP"
:set currentPublicIP "$newPublicIP"
/tool fetch url=$namecheapUpdateURL mode=https keep-result=no
} else={
/log info "DDNS: Public IP has not changed. Not updating."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment