[GH-ISSUE #317] Add MikroTik example script #247

Closed
opened 2026-02-26 09:36:55 +03:00 by kerem · 3 comments
Owner

Originally created by @tomkap on GitHub (Jun 10, 2017).
Original GitHub issue: https://github.com/nsupdate-info/nsupdate.info/issues/317

Working for MikroTik RouterOS 6.x

The script (/system script ...):

:global ddnsuser "username"
:global ddnspass "password"
:global theinterface "interface"
:global ddnshost hostname.nsupdate.info
:global ipddns [:resolve $ddnshost];
:global ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]
:if ([ :typeof $ipfresh ] = nil ) do={
   :log info ("nsupdate.info: No ip address on $theinterface .")
} else={
   :for i from=( [:len $ipfresh] - 1) to=0 do={ 
      :if ( [:pick $ipfresh $i] = "/") do={ 
    :set ipfresh [:pick $ipfresh 0 $i];
      } 
}
 
:if ($ipddns != $ipfresh) do={
    :log info ("nsupdate.info: IP = $ipddns")
    :log info ("nsupdate.info: IP-Fresh = $ipfresh")
   :log info "nsupdate.info: Update IP needed, Sending UPDATE...!"
   :global str "/nic/update\?hostname=$ddnshost&myip=$ipfresh"
   /tool fetch address=ipv4.nsupdate.info src-path=$str mode=http user=$ddnsuser \
         password=$ddnspass dst-path=("/nsupdate.info.".$ddnshost)
    :delay 1
    :global str [/file find name="nsupdate.info.$ddnshost"];
    /file remove $str
    :global ipddns $ipfresh
  :log info "nsupdate.info: IP updated to $ipfresh!"
    } else={
     :log info "nsupdate.info: dont need changes";
    }
} 

The scheduler:

/system scheduler
add interval=1m name=nsupdate.info on-event=nsupdate.info policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api start-time=startup
Originally created by @tomkap on GitHub (Jun 10, 2017). Original GitHub issue: https://github.com/nsupdate-info/nsupdate.info/issues/317 Working for MikroTik RouterOS 6.x **The script (/system script ...):** ``` :global ddnsuser "username" :global ddnspass "password" :global theinterface "interface" :global ddnshost hostname.nsupdate.info :global ipddns [:resolve $ddnshost]; :global ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ] :if ([ :typeof $ipfresh ] = nil ) do={ :log info ("nsupdate.info: No ip address on $theinterface .") } else={ :for i from=( [:len $ipfresh] - 1) to=0 do={ :if ( [:pick $ipfresh $i] = "/") do={ :set ipfresh [:pick $ipfresh 0 $i]; } } :if ($ipddns != $ipfresh) do={ :log info ("nsupdate.info: IP = $ipddns") :log info ("nsupdate.info: IP-Fresh = $ipfresh") :log info "nsupdate.info: Update IP needed, Sending UPDATE...!" :global str "/nic/update\?hostname=$ddnshost&myip=$ipfresh" /tool fetch address=ipv4.nsupdate.info src-path=$str mode=http user=$ddnsuser \ password=$ddnspass dst-path=("/nsupdate.info.".$ddnshost) :delay 1 :global str [/file find name="nsupdate.info.$ddnshost"]; /file remove $str :global ipddns $ipfresh :log info "nsupdate.info: IP updated to $ipfresh!" } else={ :log info "nsupdate.info: dont need changes"; } } ``` **The scheduler:** ``` /system scheduler add interval=1m name=nsupdate.info on-event=nsupdate.info policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api start-time=startup ```
kerem closed this issue 2026-02-26 09:36:55 +03:00
Author
Owner

@changeme commented on GitHub (May 30, 2018):

Hi. That is not a bug.
Please, do a pull request (and pray to be accepted)

<!-- gh-comment-id:393022167 --> @changeme commented on GitHub (May 30, 2018): Hi. That is not a bug. Please, do a pull request (and pray to be accepted)
Author
Owner

@ThomasWaldmann commented on GitHub (May 30, 2018):

Praying doesn't work. But a pull request would save us some work.

<!-- gh-comment-id:393076669 --> @ThomasWaldmann commented on GitHub (May 30, 2018): Praying doesn't work. But a pull request would save us some work.
Author
Owner

@tomkap commented on GitHub (Jun 4, 2018):

Sorry I'm moving to gitlab, see you there

<!-- gh-comment-id:394467509 --> @tomkap commented on GitHub (Jun 4, 2018): Sorry I'm moving to gitlab, see you there
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/nsupdate.info-nsupdate-info#247
No description provided.