Delete some specific data from address list

Hi there, so i’m trying to delete some specific ips only from a specific list name, this is what i done so far

/ip firewall address-list 
		:foreach i in=[find list="dyn_ip"] do=[ 
			$i contains the number?;
			now how can i delete a specific ip from that list?
			]
/ip firewall address-list remove [find where list="dyn_ip" && address="192.168.88.10"]

Replace “192.168.88.10” with the actual IP address you wish to remove.

If you don’t wish to do anything with the item prior to removing it, this is the most efficient way to do it.

You can also target multiple IPs by OR-ing them, e.g.

/ip firewall address-list remove [find where list="dyn_ip" && (address="192.168.88.10" || address="192.168.66.50")]

Thanks, i tried something but for some reason it;s having an strange behaviour
this is working ok

:foreach i in=[/ip firewall address-list find ] do={
	     :if ( [/ip firewall address-list get $i list] = "test" && [/ip firewall address-list get $i address] = $AIP && [/ip firewall address-list get $i address] != $BIP ) do={
		   /ip firewall address-list add address=$BIP list="test";
		   /ip firewall address-list remove $i;
	     }
      }

while this is not.. :neutral_face:

:foreach i in=[/ip firewall address-list find ] do={
	:if( [/ip firewall address-list get $i list] = "test" ) do={
		:set IPLIST [/ip firewall address-list get $i address];
		:if( $IPLIST = $AIP && $IPLIST != $BIP ) do={
			/ip firewall address-list add address=$BIP list="test";
			/ip firewall address-list remove $i;
		}
	}
}

why is this?

Any help on this please? What is wrong with my second piece of code since it has only a local variable and 1 conditional operation

Can you describe what exactly are you trying to do? Looks to me like you’re overcomplicating it.


The condition above would fail if $AIP = $BIP… Are they?

Actually… if it fails with a syntax error, it’s because you’re missing a space after the :if, i.e. you need to replace

:if( $IPLIST = $AIP && $IPLIST != $BIP ) do={

with

:if ( $IPLIST = $AIP && $IPLIST != $BIP ) do={

Doh that space killed me :neutral_face: Thanks for your observation spirit. Well i’m trying to understand ros scripting, since my pppoe connection is with a dynamic ip i need to nat some ports and for that i’m using destination address list since from one reason bounding pppoe interface to ‘in interface’ from dstnat isn’t working. In case of ip changes then at the moment of updating no-ip subdomain the dst address list will be also updated with the new ip and i was trying to wrote some lines to acomplish that. Firstly i’m searching in address list for a name, then if name matches i make some checks.. kind a useless checks but.. :slight_smile:

So as an update here is a much more eficient and simplified solution

:if ( [/ip firewall address-list find where list="dyn_ip" && address=$NewIP] ="" ) do={
	/ip firewall address-list add address=$NewIP list="dyn_ip";
}
/ip firewall address-list remove [find where list="dyn_ip" && address !=$NewIP];

Thanks again.

I’m curious about in-interface not working with dstnat rules.
I use that all of the time, and I specifically avoid using dst-address because of dynamic IP, and have never had any trouble with it.

could you post the output of /ip firewall nat export compact ?

Well i added again a rule and now is working.. :neutral_face: do not why and how, i didn’t change anything, the interface is still the same, the rule is also still the same i just deleted dst address list and set ‘in interface’ interface.. same as it was past days when i decided to use dst address list since bounding to interface wasn’t working.. i’m not crazy i know what i’m doing and i can not explain why now is working