Community discussions

MikroTik App
 
User avatar
tdeak
just joined
Topic Author
Posts: 21
Joined: Wed Jun 14, 2017 2:40 pm
Location: Hungary

IP Service Winbox cmd line new entry

Wed Oct 05, 2022 8:46 am

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.
Image

Is anybody know some cmdline switch/parameter to do this job?
 
User avatar
loloski
Member Candidate
Member Candidate
Posts: 296
Joined: Mon Mar 15, 2021 9:10 pm

Re: IP Service Winbox cmd line new entry

Wed Oct 05, 2022 9:50 am

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 
 
User avatar
loloski
Member Candidate
Member Candidate
Posts: 296
Joined: Mon Mar 15, 2021 9:10 pm

Re: IP Service Winbox cmd line new entry

Wed Oct 05, 2022 10:40 am

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
 
User avatar
tdeak
just joined
Topic Author
Posts: 21
Joined: Wed Jun 14, 2017 2:40 pm
Location: Hungary

Re: IP Service Winbox cmd line new entry

Wed Oct 05, 2022 12:35 pm

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.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: IP Service Winbox cmd line new entry

Wed Oct 05, 2022 1:10 pm

Only the simpler things are clearly readable.

I'll be back in a moment with the solution(s)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: IP Service Winbox cmd line new entry  [SOLVED]

Wed Oct 05, 2022 1:19 pm

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"
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: IP Service Winbox cmd line new entry

Wed Oct 05, 2022 1:28 pm

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)
}

Who is online

Users browsing this forum: Bolendox, cmmike, lmeira and 35 guests