Community discussions

MUM Europe 2020
 
syadnom
Member
Member
Topic Author
Posts: 407
Joined: Thu Jan 27, 2011 7:29 am

sstp IP discovery/address list script help

Thu Apr 04, 2013 7:14 pm

Goal: get all active addresses on sstp-server interfaces, add to address list without duplication

I have created a foreach loop (see below) for every item in my sstp-servers list that is running. I want to loop through these and add each IP address to an address list, but only if it does not already exist.

I have to action part:
do={/ip firewall address-list add address=[/interface sstp-server get $i client-address] list=VPNLINKS}
my problem is the if statement.

this:
:if ([/ip firewall address-list get value-name=list [find address=[/interface sstp-server get $s client-address]] = "VPNLINKS") 
only works if the address is already on the address list, if it is not, it bails with an 'interrupted \ no such item' and the scripts quits.
:foreach s in=[/interface sstp-server find where disabled=no and running=yes] do={
:local sstpsrvr $s
:local clip [/interface sstp-server get $s client-address]
:put "Server ID $sstpsrvr"
:put "Client IP address $clip"
}

Can someone help me with an if statement that doesn't bail if the find/get part has no match -OR- give some advice if I'm going about this the wrong way.

Thanks
 
ditonet
Forum Veteran
Forum Veteran
Posts: 841
Joined: Mon Oct 19, 2009 12:52 am
Location: Europe/Poland/Konstancin-Jeziorna
Contact:

Re: sstp IP discovery/address list script help

Fri Apr 05, 2013 1:38 am

ros code

:foreach s in=[/interface sstp-server find where disabled=no and running=yes] do={
:local sstpsrvr $s
:local clip [/interface sstp-server get $s client-address]
:if ([/ip firewall address-list find (list=VPNLINKS && address=$clip)] = "") do={
/ip firewall address-list add list=VPNLINKS address=$clip
};
};
HTH,
Grzegorz | MTCNA, MTCRE, MTCSE | konsultacje MikroTik Warszawa
It is a book about a Spanish guy called Manual. You should read it. - Dilbert
 
syadnom
Member
Member
Topic Author
Posts: 407
Joined: Thu Jan 27, 2011 7:29 am

Re: sstp IP discovery/address list script help

Fri Apr 05, 2013 2:42 am

perfect ditonet, thanks!

Who is online

Users browsing this forum: No registered users and 12 guests