Page 1 of 1

sstp IP discovery/address list script help

Posted: Thu Apr 04, 2013 7:14 pm
by syadnom
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

Re: sstp IP discovery/address list script help

Posted: Fri Apr 05, 2013 1:38 am
by ditonet

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,

Re: sstp IP discovery/address list script help

Posted: Fri Apr 05, 2013 2:42 am
by syadnom
perfect ditonet, thanks!