I’m trying to make a script that matches all IP addresses of the single queue with the comment “384k” and put them in a address list.
# check every Simple Queue entry
:foreach i in=[/queue simple find] do={
:local bNew "true";
# check if Queue simple comment contains 384k
:if ([:find [/queue simple find get $i comment] "384k"] != 0) do={
:local tmpAddress [/queue simple get $i target-addresses] ;
#---- if address list is empty do not check ( add address directly )
:if ( [/ip firewall address-list find ] = "") do={
/ip firewall address-list add address=$tmpAddress list=Users_384k disabled=no;
} else={
#------- check every address list entry
:foreach j in=[/ip firewall address-list find ] do={
#---------- set bNew variable to false if address exists in address list
:if ( [/ip firewall address-list get $j address] = $tmpAddress ) do={
:set bNew "false";
}
}
#------- if address is new then add to address list
:if ( $bNew = "true" ) do={
/ip firewall address-list add address=$tmpAddress list=Users_384k disabled=no
}
}
}
}
Thanks for any help!
Devil
June 4, 2012, 11:18am
2
currently i don’t have access to a mikrotik device. but if you say where exactly on this code, you experience the problem, i might be able to help.
I tested this script but add duplicate adress in adress-list
foreach i in=[/queue simple find comment="384k"] do={
local ip [queue simple get value-name=target-addresses $i ]
foreach j in=[ip firewall address-list find list=384k] do={
local tmpip [ip firewall address-list get value-name=address $j ]
if ($ip != $tmpip) do={/ip firewall address-list add address=$ip list=384k}
}
}
I don’t know when is the problem..
Devil
June 6, 2012, 8:23am
4
That script is a bit different from the script ‘machack’ provided. but anyway, since at least you mentioned where you experience the problem, i’m able to help. the trick is to check whether the address list is already added and and only if not, add the new entry:
foreach i in=[/queue simple find comment="384k"] do={
local ip [queue simple get value-name=target-addresses $i ]
foreach j in=[ip firewall address-list find list=384k] do={
local tmpip [ip firewall address-list get value-name=address $j ]
if (($ip != $tmpip) && ([/ip firewall address-list find list=384k address=$ip] = "")) do={
/ip firewall address-list add address=$ip list=384k
}
}
}
Devil:
That script is a bit different from the script ‘machack’ provided. but anyway, since at least you mentioned where you experience the problem, i’m able to help. the trick is to check whether the address list is already added and and only if not, add the new entry:
foreach i in=[/queue simple find comment="384k"] do={
local ip [queue simple get value-name=target-addresses $i ]
foreach j in=[ip firewall address-list find list=384k] do={
local tmpip [ip firewall address-list get value-name=address $j ]
if (($ip != $tmpip) && ([/ip firewall address-list find list=384k address=$ip] = "")) do={
/ip firewall address-list add address=$ip list=384k
}
}
}
run this script two time, and check the adress-list.
Devil
June 7, 2012, 12:20pm
6
Alright, i rewrote the whole thing for you. it now supports any possible type of targe-address: ( single address, multiple addresses, and subnets). lets just say it was tricky
:local lenip;
:foreach i in=[/queue simple find comment="384k"] do={
:foreach ip in=[/queue simple get value-name=target-addresses $i ] do={
:set lenip [:len $ip];
:if ([:pick $ip ($lenip-3) $lenip] = "/32") do={
:set ip [:pick $ip 0 ($lenip-3)];
}
:if ([/ip firewall address-list find list=384k address=$ip] = "") do={
/ip firewall address-list add address=$ip list=384k
}
}
}
we should can apply the pcq for the V5.0 and above…
as understand from mikrotik, version above 5 can do per ip queue with pcq already…
/interface bridge settings set use-ip-firewall=yes
/interface bridge settings set use-ip-firewall-for-vlan=yes
/ip firewall mangle add action=mark-packet chain=prerouting disabled=no in-interface=wlan1-LAN new-packet-mark=client_upload passthrough=yes
/ip firewall mangle add action=mark-packet chain=prerouting disabled=no in-interface=ether1-WAN new-packet-mark=client_download passthrough=yes
/queue type add kind=pcq name=PCQ_download pcq-burst-rate=0 pcq-burst-threshold=0 pcq-burst-time=10s pcq-classifier=dst-address pcq-dst-address-mask=32 pcq-dst-address6-mask=128 pcq-limit=50 pcq-rate=1M pcq-src-address-mask=32 pcq-src-address6-mask=128 pcq-total-limit=50000
/queue type add kind=pcq name=PCQ_upload pcq-burst-rate=0 pcq-burst-threshold=0 pcq-burst-time=10s pcq-classifier=src-address pcq-dst-address-mask=32 pcq-dst-address6-mask=128 pcq-limit=50 pcq-rate=1M pcq-src-address-mask=32 pcq-src-address6-mask=128 pcq-total-limit=50000
/queue simple add burst-limit=0/0 burst-threshold=0/0 burst-time=0s/0s direction=both disabled=no interface=all limit-at=0/0 max-limit=0/0 name=“local download” packet-marks=“” parent=none priority=8 queue=PCQ_upload/PCQ_download target-addresses=0.0.0.0/0 total-queue=default-small
/queue tree add burst-limit=0 burst-threshold=0 burst-time=0s disabled=no limit-at=0 max-limit=50M name=queue1 packet-mark=client_download parent=global-in priority=8 queue=PCQ_download
/queue tree add burst-limit=0 burst-threshold=0 burst-time=0s disabled=no limit-at=0 max-limit=50M name=queue2 packet-mark=client_upload parent=global-out priority=8 queue=PCQ_upload
Dear mikrotik…
is this script correct that it will limit each user 1Mbps as we got 50Mbps bandwidth…
and if we got 100 user online at the same time, then each will equivalent to have 512kbps?
thanks…