Community discussions

MikroTik App
 
User avatar
machack
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 65
Joined: Fri Jun 01, 2007 9:35 pm
Location: San Luis Argentina
Contact:

Need Help, to get IP adddress from simple queue and...

Mon Jun 04, 2012 4:47 am

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
Member Candidate
Member Candidate
Posts: 170
Joined: Thu Jul 21, 2011 9:13 am

Re: Need Help, to get IP adddress from simple queue and...

Mon Jun 04, 2012 2:18 pm

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.
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: Need Help, to get IP adddress from simple queue and...

Wed Jun 06, 2012 4:45 am

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
Member Candidate
Member Candidate
Posts: 170
Joined: Thu Jul 21, 2011 9:13 am

Re: Need Help, to get IP adddress from simple queue and...

Wed Jun 06, 2012 11:23 am

I don't know when is the problem..
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
    }
  }
}
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: Need Help, to get IP adddress from simple queue and...

Wed Jun 06, 2012 8:20 pm

I don't know when is the problem..
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
Member Candidate
Member Candidate
Posts: 170
Joined: Thu Jul 21, 2011 9:13 am

Re: Need Help, to get IP adddress from simple queue and...

Thu Jun 07, 2012 3:20 pm

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
    }
  }
}
 
angboontiong
Forum Guru
Forum Guru
Posts: 1136
Joined: Fri Jan 16, 2009 9:59 am

Re: Need Help, to get IP adddress from simple queue and...

Fri Jun 08, 2012 4:13 pm

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...

Who is online

Users browsing this forum: No registered users and 3 guests