MrOsis
October 27, 2013, 11:06pm
1
Hi!
Im trying to compare two address lists and delete match entries… My code look like this:
:local blackIP
:local visitedIP
:foreach i in=[/ip firewall address-list find list=blocked] do={
:set blackIP [/ip firewall address-list get $i address]
:foreach j in=[/ip firewall address-list find list=block_visited] do={
:set visitedIP [/ip firewall address-list get $j address]
:if ($blackIP=$visitedIP) do={/ip firewall address-list find list=blocked{
remove [find address=$blackIP]
}
}
}
}
It compares, it find matches, BUT dont delete the record… whats wrong here?
mrz
October 28, 2013, 12:23pm
3
This part doesnt look right
:if ($blackIP=$visitedIP) do={/ip firewall address-list find list=blocked{
remove [find address=$blackIP]
}
}
Should be something like
:if ($blackIP=$visitedIP) do={
/ip firewall address-list remove [find address=$blackIP];
}
MrOsis
October 28, 2013, 12:53pm
4
Hi, thanks for answer, but - if I have 2 exact addresses, but in different address-lists - this will delete both, isnt?
MrOsis
October 28, 2013, 1:06pm
5
SOLVED!!!
Correct code:
:local blackIP
:local visitedIP
:foreach i in=[/ip firewall address-list find list=blocked] do={
:set blackIP [/ip firewall address-list get $i address]
:foreach j in=[/ip firewall address-list find list=block_visited] do={
:set visitedIP [/ip firewall address-list get $j address]
:if ($blackIP=$visitedIP) do={
/ip firewall address-list remove [find list=blocked address=$blackIP];
}
}
}
}
Thanks for help!
mrz
October 28, 2013, 1:16pm
6
Actually you do not need to run find again, since $i already contains needed id to remove address
So you can just:
/ip firewall address-list remove $i
MrOsis
October 28, 2013, 1:34pm
7
Even better
And one more question, from different opera: firewall filter can read data (address list) only from section “address list” or there is some way to force it to read data directly from file? (I dont like long address lists in direct view)?
mrz
October 28, 2013, 1:56pm
8
No, firewall cannot read address list from file