Page 1 of 1

counting routes

Posted: Fri Nov 12, 2004 6:16 pm
by cheinzle
Is there any way to count the number of routes in the routing table?

Posted: Fri Nov 12, 2004 6:34 pm
by cheinzle
If I use the following to find all routes with a distance setting of 110:

> :set i [/ip route find distance=110]

then print the results:

> :put $i
*170,*182,*17A,*179,*177,*178,*16F,*17E,*176,*172,*175,*174,*173,*171,*17D

I get a list of route numbers. Can I then count these?

Posted: Mon Nov 15, 2004 9:20 am
by Eugene
{:local a; :set a 0; :foreach i in [/ip route find distance=110] do={:incr a}; :put $a; :unset a}

Posted: Mon Nov 15, 2004 9:31 am
by Eugene
In v2.9 new command len is available which greatly simplifies the task above, exempli gratia:
:put [:len [/ip route find interface=ether1]]

Posted: Wed Nov 24, 2004 6:20 pm
by lastguru
Why not to use the count-only parameter for the print command?

[admin@mikrotik] ip route> print count-only
18
[admin@mikrotik] ip route>

Posted: Thu Nov 25, 2004 9:33 am
by normis
very nice latsguru :) the simple solution is sometimes the best

Posted: Thu Nov 25, 2004 8:26 pm
by [ASM]
Why not to use the count-only parameter for the print command?

[admin@mikrotik] ip route> print count-only
18
[admin@mikrotik] ip route>
or :
/ip route print count-only from=[/ip route find distance=110]

Posted: Fri Dec 03, 2004 6:00 pm
by cheinzle
thanks. very nice.

Re:

Posted: Wed Sep 01, 2021 8:50 pm
by rextended
/ip route print count-only from=[/ip route find distance=110]

Or simply...
/ip route print count-only where distance=110