IP Service Winbox cmd line new entry

Dear Members,

I’m trying to build a script which resolves a dyndns address store it on a variable and add it to NEW allowed address (and removes the old one) from IP Service / Winbox / allowed address.

I have the resolver:

:global myip [:resolve domain-name=myip.selfip.net server=8.8.8.8]

I can add it to allowed address with:

 /ip service/set winbox address=$myip

But my problem is that this replaces the existing records and not addind a new line.

Is anybody know some cmdline switch/parameter to do this job?

there is no direct way you have to put it in an array, this is not the answer you are looking for but it’s a step in right direction this command will add this two address from the list

/ip service/set address=1.1.1.2,1.1.1.1 winbox

i’m not a scripting guru but i put a stab on it, here is the little code to do it

:global myip [:resolve domain-name=myip.selfip.net server=8.8.8.8]
:global address [/ip service/get [find name="winbox" value-name]]
:global list [:pick $address 1]
:set $list ($list,$myip)
/ip service/set address=$list winbox

Hi loloski,
thanks for your effort. After some tweak the script working but unfortunately still replace the line to only one (the variable).

Here is the script so far:

:global myip [:resolve domain-name=myip.selfip.net server=8.8.8.8]
:global address [/ip service find name="winbox" value-name]
:global list [:pick $address 1]
:set $list ($list,$myip)
/ip service set address=$list winbox

So this is working but still replace the whole address list. I’m trying now to manipulate further..

edit: problem will be somewhere in “winbox” value. Unfortunately somewhere the syntax will be the issue to read correctly the value of “Available From” table.

Only the simpler things are clearly readable.

I’ll be back in a moment with the solution(s)

1st mode: is knowed already the allowed IPs:

{
:local always   "0.0.0.0/0,192.168.88.0/24"
:local dnsname  "one.one.one.one"
:local resolver "8.8.8.8"

:global resolved "127.0.0.1"
[:execute ":global resolved;:set resolved [:resolve $dnsname server=$resolver]"]
:delay 2s

/ip service set winbox address="$always,$resolved"
}

2nd way: idiocy, add other IPs without removing the unused ones.

{
:local dnsname  "www.mikrotik.com"
:local resolver "8.8.8.8"

:global resolved "127.0.0.1"
[:execute ":global resolved;:set resolved [:resolve $dnsname server=$resolver]"]
:delay 2s

/ip service
:local actualips [get winbox address]
set winbox address=($actualips,$resolved)
}