What is wrong with this Script ????

I get this script from a friend :

:local traf;
/queue simple
{
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=(“192.168.100.” . $i)] != “”) do={
:set traf [get [find target-addresses=(“192.168.100.” . $i)] total-bytes]
:if ($traf > 5242880) do = {
set [find target-addresses=(“192.168.100.” . $i)] max-limit= 32000/64000
}
}
}

}

This script should check all the ip for its usage and when usage exceeds 5MB ( for test )
It should create a simple queue with that ip to limit speed to 64K.

I add a new schedule and past this script in the field On Event and run it every 10 sec ( For Check )
I test but the download exceeds 10MB and no new simple queue created.

I have mikrotik 6.28 server with simple configuration :

/ip address
add address=192.168.100.1/24 interface=Mangers network=192.168.100.0
add address=192.168.1.50/24 interface=External network=192.168.1.0
/ip dns
set allow-remote-requests=yes servers=208.67.222.222,208.67.220.220
/ip firewall nat
add action=masquerade chain=srcnat out-interface=!Mangers
add action=redirect chain=dstnat dst-port=80 in-interface=External protocol=
tcp to-ports=8080
add action=redirect chain=dstnat dst-port=80 protocol=tcp to-ports=8080
/ip proxy
set cache-on-disk=yes cache-path=disk2 enabled=yes
/ip route
add distance=1 gateway=192.168.1.1

I do not what is wrong..??
Please help

Since RouterOS 6.x simple queues target-addresses and interface parameters are joined into one
“target” parameter.

This code will work if there will be target with adrress=(192.168.100." . $i."/32) and total-bytes more than 5242880

{
:local traf;
:for i from=1 to= 254 do={
:if ([:len [/queue simple find target=(“192.168.100.” . $i.“/32”)]]>0) do={
:if ([/queue simple get [find target=(“192.168.100.” . $i.“/32”)] total-bytes]>5242880) do={/queue simple set [/queue simple find target=(“192.168.100.” . $i.“/32”)] max-limit=32000/64000;}
}
}
}

I Try your script but it is not working also
I am testing from a pc with ip 192.168.100.50 by download and youtube and brwosing is this ok ??

Do I have to make simple queue for all the IP’s in network 192.168.100.0/24
Or the script will create a simple queue for the ip it get ???

By the way my network is /24 I try your script with /24 instead of /32 bit also not working
I do not know where is the problem ??

Please help

This the photo for my schedule is this ok ??

Put the code into its own script and the script name put into on event field.

I do this yesterday but no way it is not working, check photo
I do one trail I replace the > sign with < and add manually a simple queue
With the IP the I am testing from it 192.168.100.50 and it works and changes the queue speed
But without any traffic ( this is to check script errors ).

Sorry to distrib you, But I need this script.
Please help if you have this script working on your server send me your server
Settings to try it in my server.
Thanks

Try this:

:local traf 5242880;
:local qqueue;
:local tgt;
:for i from=1 to= 254 do={
  :set tgt ("192.168.100.$i/32");
  :set qqueue [/queue simple find target=$tgt];
  :if ([:len $qqueue]>0) do={
    :if ([/queue simple get $qqueue total-bytes]>$traf) do={
         :log info ("Setting queue limit for $tgt");
        /queue simple set $qqueue max-limit=32000/64000;}
    }
  }
}

I try also not working I think the problem is the total-bytes when
I try ---- /queue simple> get number=0 value-name=total-bytes from
the terminal it show nothing and from browser I consumed about 100MB

Also in the queue status there no traffic check this photo :

So if there is no data flow, then there is no data to limit :slight_smile: Simple.

I get it
IT was not the script it was the queue type it should be Default.
In Mikrotik 6.28 When you create a simple queue it makes its
Default type — Default-Small.

When I change the type to Default the Script work very well, and
I think the first script will work also.

Thank you very much for your patient with me.

Mr. BartoszP


I need another thing, I need a script to change all my simple queues
max-limit to unlimited so I do this one but not working :

:for i from=1 to= 300 do={
/queue simple set number=“$i” max-limit=0/0
}

can you check it

Check this

:local qqueue;
:foreach qqueue in=[/queue simple find] do={
  /queue simple set $qqueue max-limit=0/0
}

Yes It Works perfect
Many thanks to all of you and this respective forum

If you want to just modify all matches, you can also simply use

/queue simple set [/queue simple find] max-limit=0/0

(which is also more efficient)

Thanks you very much