Community discussions

MikroTik App
 
wwj
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 55
Joined: Mon May 05, 2014 6:37 am

How to do a Fuzzy query

Fri Apr 02, 2021 9:09 am

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>
 
wwj
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 55
Joined: Mon May 05, 2014 6:37 am

Re: How to do a Fuzzy query

Fri Apr 02, 2021 9:13 am

in other system,have the command like

show ip routing-table | include 172.17.

how to do this in routeros
 
nescafe2002
Forum Veteran
Forum Veteran
Posts: 897
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: How to do a Fuzzy query

Fri Apr 02, 2021 9:42 am

Use the in keyword for subnet matching.

E.g.

/ip route print where 172.17.0.0/16 in dst-address
 
wwj
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 55
Joined: Mon May 05, 2014 6:37 am

Re: How to do a Fuzzy query  [SOLVED]

Fri Apr 02, 2021 11:33 am

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" )
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: How to do a Fuzzy query

Fri Apr 02, 2021 12:45 pm

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 \.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10194
Joined: Mon Jun 08, 2015 12:09 pm

Re: How to do a Fuzzy query

Fri Apr 02, 2021 4:18 pm

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.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: How to do a Fuzzy query

Fri Apr 02, 2021 4:49 pm

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

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
 
pe1chl
Forum Guru
Forum Guru
Posts: 10194
Joined: Mon Jun 08, 2015 12:09 pm

Re: How to do a Fuzzy query

Fri Apr 02, 2021 5:56 pm

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.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: How to do a Fuzzy query

Fri Apr 02, 2021 6:29 pm

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.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10194
Joined: Mon Jun 08, 2015 12:09 pm

Re: How to do a Fuzzy query

Sat Apr 03, 2021 12:22 pm

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.
 
wwj
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 55
Joined: Mon May 05, 2014 6:37 am

Re: How to do a Fuzzy query

Tue May 25, 2021 12:06 pm

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"

Who is online

Users browsing this forum: No registered users and 23 guests