Page 1 of 1
Using "find" to match partial comment
Posted: Mon Oct 24, 2005 6:59 pm
by butche
I would like to accomplish the following:
I have firewall rules as follows (example):
/ip firewall rule test
add src-address=10.10.10.10/32 action=drop comment="ACCEPT me"
add action=drop comment="DROP the rest"
What I would like to do is use find to allow me to manipulate only those items in the list that have "DROP" in the comment. I will not have the full text of the comments, as they are different, but ALL will have a common portion (i.e.: DROP or ACCEPT). I looked in the scripting manual, but could not get much beyond the fact that it seems possible. Any insights?
Posted: Tue Oct 25, 2005 1:02 pm
by Eugene
[admin@MA_GW] > :put [:find "do not ACCEPT me" "ACCEPT"]
7
[admin@MA_GW] > :put [:find "do not ACCEPT me" "not found"]
[admin@MA_GW] >
:find string substring searches for the first inclusion of substring in the string and returns position at which a match has occured.
Hope this helps.
Posted: Tue Oct 25, 2005 5:29 pm
by butche
[admin@MA_GW] > :put [:find "do not ACCEPT me" "ACCEPT"]
7
[admin@MA_GW] > :put [:find "do not ACCEPT me" "not found"]
[admin@MA_GW] >
Ok...any idea how I get find to parse the list of firewall rules comments?
In your example, you have a known string. Something like this (this doesn't work...)
/ip firewall filter set [:find <comment=UNKNOWN> "SOMETHING"] action=allow
In other words, I want to look through all rules for the comments that contain "SOMETHING" and do something with those rules.
Posted: Tue Oct 25, 2005 6:05 pm
by Eugene
Well, nothing easier than that:
:foreach i in [/ip firewall filter find] do={
:if ("." . [:find [/ip firewall filter get $i comment] "SOMETHING"] . "."!="..") do={
/ip firewall filter set $i action=accept
}
}
Posted: Tue Oct 25, 2005 6:22 pm
by butche
Well, nothing easier than that:
:foreach i in [/ip firewall filter find] do={
:if ("." . [:find [/ip firewall filter get $i comment] "SOMETHING"] . "."!="..") do={
/ip firewall filter set $i action=accept
}
}
:D
You da' man! :P
Re: Using "find" to match partial comment
Posted: Mon Dec 03, 2018 3:59 am
by kiwistag
Hi, how would this work if you wanted a MAC address from say a DHCP lease? That way it'd be possible to run WOL to a classroom/office area based on computer name.
:foreach i in [/ip dhcp-server lease mac find] do={
:if ("." . [:find [/ip dhcp-server lease get $i active-host-name] "Student-Class2"] . "."!="..") do={
*******
/tool wol mac=$j interface=LAN
}
}
I think I need another search call to first get the MAC address off the list then pass it to the final command. Still quite new to it so please excuse the ignorance to the extra command needed (*****)
Re: Using "find" to match partial comment
Posted: Mon Dec 03, 2018 12:14 pm
by sebastia
api allow to search on number of parameters, including comment. The match can be full or partial. Ex:
print where comment~"est_rel"