Skip to content

Instantly share code, notes, and snippets.

@frosty024
Forked from luispaulorsl/ddns_updater.rsc
Last active May 31, 2024 21:31
Show Gist options
  • Save frosty024/3a3fd7ad126956ef3765c32f3cb14a1a to your computer and use it in GitHub Desktop.
Save frosty024/3a3fd7ad126956ef3765c32f3cb14a1a to your computer and use it in GitHub Desktop.
Mikrotik/RouterOS Script to update DDNS on No-IP (noip.com)
# No-IP DDNS Updater
# http://www.noip.com/integrate/
:global publicIP;
:global abortUpdate;
:if ([:typeof $abortUpdate] != "bool") do={
:set $abortUpdate false;
}
:if ($abortUpdate) do={
:error "DDNS: Update aborted. Intervention required.";
}
:local currentIP;
:local targetInterface "ether1";
:local ddnsUser "yourusername";
:local ddnsPass "yourpassword";
:local ddnsHost "youraddress";
:local ddnsURL "http://dynupdate.no-ip.com/nic/update?hostname=$ddnsHost&myip=$currentIP";
:if ($targetInterface = "ether1") do={
:local response [/tool fetch url="http://ip1.dynupdate.no-ip.com/" as-value output=user];
:if ($response->"status" = "finished") do={
:set currentIP ($response->"data");
} else={
:set currentIP "";
}
} else={
:set currentIP [/ip address get [/ip address find interface=$targetInterface] address];
:if ([:typeof $currentIP] = nil) do={
:error "DDNS: No IP obtained.";
} else={
:set $currentIP [:pick [:tostr $currentIP] 0 [:find [:tostr $currentIP] "/"]];
}
}
:if ($currentIP != $publicIP) do={
:local response [/tool fetch url=$ddnsURL user=$ddnsUser password=$ddnsPass as-value output=user];
:if ($response->"status" = "finished") do={
:local data ($response->"data");
:set $abortUpdate (!([:pick $data 0 4] = "good" || [:pick $data 0 5] = "nochg"));
:set $publicIP $currentIP;
:log info "DDNS: Update succeeded."
} else={
:log error "DDNS: Update failed.";
}
} else {
:log info "DDNS: No IP change.";
}
@frosty024
Copy link
Author

frosty024 commented May 28, 2024

April 19, 2024

Replace (do not remove the quotes):

  • yourusername with NO-IP username
  • yourpassword with NO-IP password
  • youraddress with NO-IP host (the full address)

Tested on:

  • firmware arm64-7.14.3 running on an RB5009UPr+S+IN
  • firmware mipsbe-6.49.14 running on an RB2011UiAS-2HnD
  • firmware mipsbe-6.49.14 running on an RB951G-2HnD

Notes:

  • Changed IP check from original author's website to NO-IP's official website
  • Assumption: WAN = ether1 (if WAN isn't ether1, change it on lines 16 and 23)
  • Permissions: Read/Write/Test (if still not working, may need Policy permission as well)
  • Scheduled task will require the same permissions as above. Recommended task interval: 6 hours

Beware that certain special characters may not work on a 'tik without first escaping ( \ ) them in pre-7.0 firmware.
https://wiki.mikrotik.com/wiki/Manual:Scripting#Constant_Escape_Sequences

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment