-
-
Save hsantosdias/23f28d429a6fb202e4f54992f1f326dc 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 "<interface | auto>"; | |
:local ddnsUser "<username>"; | |
:local ddnsPass "<password>"; | |
:local ddnsHost "<hostname>"; | |
:local ddnsURL "http://dynupdate.no-ip.com/nic/update?hostname=$ddnsHost&myip=$currentIP"; | |
:if ($targetInterface = "auto") do={ | |
:local response [/tool fetch url="http://luispaulo.net/ip" 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