How to do a Fuzzy query

for example

[admin@wwj] /ip route> pr where static
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit

DST-ADDRESS PREF-SRC GATEWAY DISTANCE

0 ADS 0.0.0.0/0 pppoe-out1-a 1
1 A S 12.193.16.4/32 pppoe-out1-a 5
2 A S 172.13.1.0/24 pppoe-out1-a 1
3 S 172.17.2.200/32 pppoe-out2-wwj 1
4 A S 172.17.2.200/32 pppoe-out1-a 3
5 S 172.17.65.252/32 pppoe-out2-wwj 1
6 A S 172.17.65.252/32 pppoe-out1-a 3
7 X S 172.21.143.143/32 172.3.4.1 1
8 A S ;;; vpn-server
172.21.192.2/32 pppoe-out1-a 1
9 S ;;; vpn-server
172.21.192.2/32 pppoe-out2-wwj 1

if i just want to show the result of beginwith 172.17.* ,how to input the command

[admin@wwj] /ip route> pr where static dst-address=172.17.
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit

DST-ADDRESS PREF-SRC GATEWAY DISTANCE

[admin@wwj] /ip route> pr where static dst-address="172.17."
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit

DST-ADDRESS PREF-SRC GATEWAY DISTANCE

[admin@wwj] /ip route> pr where static dst-address="172.17.*"
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit

DST-ADDRESS PREF-SRC GATEWAY DISTANCE

[admin@wwj] /ip route> pr where static dst-address=172.17.*
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit

DST-ADDRESS PREF-SRC GATEWAY DISTANCE

[admin@wwj] /ip route>

in other system,have the command like

show ip routing-table | include 172.17.

how to do this in routeros

Use the in keyword for subnet matching.

E.g.


/ip route print where 172.17.0.0/16 in dst-address

thanks,but it’s not my mind

I have found the answer
/ip rou pr where dst-address ~ “172.17.”
this char “~” is the key , (same as “include” )

This will fail for two reason.

  1. It will take IP with your search in the middle, like 10.172.17.13.1
  2. Dot will be like any character, so it will hit on 172.172.10.10 as well as 172.17.1.10

Since this is regex, you need to do the following.

/ip route print where dst-address ~ "^172\.17\."

^ This to make it from start of field, and escape the dot like this .

Actually that has to be “^172\.17\.”
Inside " the \ is evaluated to \ and then the . means a literal .
The construct dst-address in 172.17.0.0/16 is much better in general, because it can also apply to subnet masks not aligned with byte boundaries.
It is also likely more efficient, which can be important when the routing table is very large.

@pe1chl
You are correct about the double \
Was just written without testing :slight_smile:

This works:

/ip firewall address-list print where address~"^42.117\\."

This does not work for me

/ip firewall address-list print where 42.117.0.0/16 in address
/ip firewall address-list print where "42.117.0.0/16" in address

I do not know where the idea of the xx.xx.xx.xx/16 in address came from, it of course should be address in xx.xx.xx.xx/16.

It must be my head that was not on the correct place

This works

/ip firewall address-list print where address in 42.117.0.0/16

and I guess its faster than regex.

Yes, I think so, because for the “address in subnet” match one would expect the address is compared as a 32-bit number (first an AND with the subnet mask and then a compare) while for the ~ match each address first has to be converted from binary number to text string, and then a regexp match has to be done on the text string.
And that only works in the command itself, and not e.g. in winbox when using a filter. They probably did not implement that because it is so inefficient.

Thank you, teachers

I learned a lot more

1、 Fuzzy query use “~”
2、address in x.x.x.x/x or x.x.x.x in address or x.x.x.x/x in address , all can works well
3、“^23” means the “begin with 23”
4、“10.1.1.1” “2.10.5.2” “3.101.1.2”
4.1 if use “10.” can match “10.1.1.1” “2.10.5.2” “3.101.1.2” the " . " is not work ,
4.2 if use “10\.” , it can match “10.1.1.1” “2.10.5.2” ,but can’t match “3.101.1.2”
4.3 if use “^10” can just match “10.1.1.1”