I have searched the web, but was unable to find a solution to the following:
I have three address-lists configured, each driving workstations through three different WAN ports.
I just need a simple quick way (without using the GUI, so through the terminal) to find out to which list any particular IP belongs.. In other words, somthing like:
/ip firewall address-list get list where address=192.168.x.x
and as a return to the above, just spit out: list1, list2 or list3.
hope this makes sense, but let me know if you have any suggestions.
Thanks,
Kenneth
Although it’s normally not a good idea to spoon feed such scripts, I’ve been wondering on what kind of sample scripts to work on that I might practice scripting with… so thank you for providing me with this opportunity, although I also kind’a feel gulty of taking it away from you .
Here’s a script that does just what you said:
:local ip 192.168.x.x
:local result ""
:local delimiter ", "
:local fullList [/ip firewall address-list print as-value where address=$ip]
:foreach entry in $fullList do {
:foreach part in $entry do {
:local name [:pick $part 0 [:find $part "="]]
:local value [:pick $part ([:find $part "="]+1) [:len $part]]
:if ($name="list") do {
:set result ($result . $value . $delimiter)
};
};
};
:put [:pick $result 0 ([:len $result]-[:len $delimiter])]
Just replace the first line with whichever IP you need. You could declare that variable as a global one, but in that case, you’d have to set it right before running the script.
Hi, i got some error if there is the IP on multiple list,
:put [/ip firewall address-list get value-name=list [find address=1.1.1.1]]
invalid internal item number
how i can see all of list that contains the ip?
please help me, thx before