-
-
Save frosty024/3a3fd7ad126956ef3765c32f3cb14a1a to your computer and use it in GitHub Desktop.
Mikrotik/RouterOS Script to update DDNS on No-IP (noip.com)
This file contains hidden or 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
# 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."; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
April 19, 2024
Replace (do not remove the quotes):
Tested on:
Notes:
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