Community discussions

MikroTik App
 
texmeshtexas
Member Candidate
Member Candidate
Topic Author
Posts: 151
Joined: Sat Oct 11, 2008 11:17 pm

Find address list to which an IP belongs

Mon Feb 06, 2023 6:19 am

In winbox if I filter in /ip/firewall/address-list for and address that is part of a subnet, it displays properly.

Example: filter for 100.72.58.74
there is an address list that contains 100.64.0.0/10 so the list and subnet to which that IP is part of is displayed.

However, in a script I'm trying to do the same with
:put [/ip/firewall/address-list print where address=100.72.58.74]
or
:put [/ip/firewall/address-list get value-name=list [find address=100.72.58.74]]

both return nothing.
Is there a way to replicate what can be done in winbox?
 
texmeshtexas
Member Candidate
Member Candidate
Topic Author
Posts: 151
Joined: Sat Oct 11, 2008 11:17 pm

Re: Find address list to which an IP belongs

Mon Feb 06, 2023 6:20 am

I have seen this post viewtopic.php?p=287021&hilit=find+addre ... gs#p287021
and it does not seem to work either.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Find address list to which an IP belongs

Mon Feb 06, 2023 1:14 pm

You must not use "=" if the IP is not exactly the address list entry...
Obviously 1.2.3.4 is not = to 1.2.3.0/24

Is easy, you must search oe address that is in the pool or identical to the single address...:
/ip firewall address-list print where ( (100.72.58.74 in address) or (100.72.58.74=address) )

For use on scripting:
/ip firewall address-list
{
    :local addr  100.72.58.74
    :local nlist ({})
    :foreach index in=[find where ( ($addr in address) or ($addr=address) )] do={
        :set nlist ($nlist,[get $index list])
    }
    :put "The address $addr is on lists $[:tostr $nlist]"
}
 
texmeshtexas
Member Candidate
Member Candidate
Topic Author
Posts: 151
Joined: Sat Oct 11, 2008 11:17 pm

Re: Find address list to which an IP belongs

Mon Feb 06, 2023 3:44 pm

Thank you Rextended, that works perfectly! I was not aware of the "in" operator.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Find address list to which an IP belongs

Mon Feb 06, 2023 4:33 pm

Who is online

Users browsing this forum: JDF and 26 guests