Community discussions

MikroTik App
 
jonah1810
newbie
Topic Author
Posts: 29
Joined: Tue Jul 30, 2019 10:19 pm

Help me make this script faster

Sun Nov 15, 2020 4:08 am

{
	:local addr
	:for x from=101 to=119 step=2 do={
	:for i from=0 to=254 do={
	:set addr value=("10.100.$x." . $i)
	:if (0=[pick  [/ip firewall mangle print count-only where src-address=($addr)] 0]) do={
	:if [/ip firewall address-list find address=($addr) = true && list="Streamer"] do={
	[/ip firewall mangle add action=passthrough chain=forward src-address=($addr)]
	}
   }
  }
 }
}
First checks if src address is in mangle and if it isn't puts all addresses with list="Streamer" into Mangle for tracking purposes.

this scans a lot of IP's and takes about 10s on my 4011. I was trying to figure out a foreach loop to go through every address-list entry (Instead of every possible address) but I cannot for the life of me get the foreach loop to do what I want.
 
User avatar
BartoszP
Forum Guru
Forum Guru
Posts: 1895
Joined: Mon Jun 16, 2014 1:13 pm
Location: Poland

Re: Help me make this script faster

Sun Nov 15, 2020 10:42 am

:for i from=0 to=254 do={
	:set addr value=("10.100.$x." . $i)
	:if (0=[pick  [/ip firewall mangle print count-only where src-address=($addr)] 0]) do={
You do a lot of scans with "pick" ... 10*255 of them
Just an idea ... try to substitute it with foreach loop with proper where clause.
Real admins use real keyboards.
To quote or not to quote, there is the topic: viewtopic.php?f=2&t=168474

Who is online

Users browsing this forum: No registered users and 86 guests