Community discussions

MikroTik App
 
ransom
newbie
Topic Author
Posts: 33
Joined: Sun Jul 29, 2007 12:26 pm

New to scripting in RouterOS

Sun Jul 29, 2007 12:32 pm

Hi, Im learning this scripting option of routerOS. Please help me with the following: in the winbox i use the following script

/ip firewall filter disable 1

as a simple script to disable rule 1 in my fw. i click run, it shows run 1 times. but the rule doesnt disable? Same with bandwidth management using Queues. I created a queue, paste the script exactly as it is on wiki.mikro... and click run, nothing! even in scheduler, paste the script, run every 10s. it shows ran 10 times etc but no result.

What am I missing or doing wrong?
 
User avatar
balimore
Forum Veteran
Forum Veteran
Posts: 884
Joined: Mon Apr 10, 2006 3:38 am

Re: New to scripting in RouterOS

Sun Jul 29, 2007 12:45 pm

----
Hai fren
better, when you will make enable/disable any rule with find comment first.
don't use number of rule
i have sample for it here: http://forum.mikrotik.com/viewtopic.php?f=9&t=17102

regards
Hasbullah.com
----

Hi, Im learning this scripting option of routerOS. Please help me with the following: in the winbox i use the following script

/ip firewall filter disable 1

as a simple script to disable rule 1 in my fw. i click run, it shows run 1 times. but the rule doesnt disable? Same with bandwidth management using Queues. I created a queue, paste the script exactly as it is on wiki.mikro... and click run, nothing! even in scheduler, paste the script, run every 10s. it shows ran 10 times etc but no result.

What am I missing or doing wrong?
 
ransom
newbie
Topic Author
Posts: 33
Joined: Sun Jul 29, 2007 12:26 pm

Re: New to scripting in RouterOS

Sun Jul 29, 2007 1:18 pm

i found nothing in your article about the find statement. Please show me how I will find the rule and then disable it with scripting

Thanx!
 
User avatar
balimore
Forum Veteran
Forum Veteran
Posts: 884
Joined: Mon Apr 10, 2006 3:38 am

Re: New to scripting in RouterOS

Sun Jul 29, 2007 1:36 pm

----
Hai again,
at last script will action enable any rules, i use find comment.
assumnsy you have it comment first. :wink:
thanks your time for

at that script i wrote 4 caracters: e.g enable i wrote enab, disable i wrote disa

regards
Hasbullah.com
----
i found nothing in your article about the find statement. Please show me how I will find the rule and then disable it with scripting

Thanx!
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7053
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: New to scripting in RouterOS

Sun Jul 29, 2007 1:45 pm

add comment to your first firewall rule, for example myComment

After that you can use command:
/ip firewall filter disable [ /ip firewall filter find comment=myComment ] ;
/ip firewall filter disable 1 doesn't work, because /ip firewall filter print must be executed first. Print command writes all filters to internal buffer. But this works only when you type commands from console and won't work as standalone script.
 
ransom
newbie
Topic Author
Posts: 33
Joined: Sun Jul 29, 2007 12:26 pm

Re: New to scripting in RouterOS

Sun Jul 29, 2007 7:07 pm

Aaah! the internal buffer makes sense - not being at the console yet no buffer :)

cool!

now lemme go try
 
ransom
newbie
Topic Author
Posts: 33
Joined: Sun Jul 29, 2007 12:26 pm

Re: New to scripting in RouterOS

Sun Jul 29, 2007 9:51 pm

Ok so this works.

Now for the next test: Bandwidth management using Queues.

I created a simple queue for the 192.168.0.0/24 IP range. I paste the script from the site and modified the 100MB (in bytes) to 1 to activate the script earlier. Nothing happends to the queues! its suppose to limit to 64k download.

Any Suggestions?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7053
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: New to scripting in RouterOS

Mon Jul 30, 2007 9:50 am

post your queue rule and script.
 
ransom
newbie
Topic Author
Posts: 33
Joined: Sun Jul 29, 2007 12:26 pm

Re: New to scripting in RouterOS

Mon Jul 30, 2007 10:57 am

Queue rule:

name="queue1" target-addresses=192.168.0.0/24 dst-address=0.0.0.0/0
interface=all parent=none direction=both priority=8
queue=default-small/default-small limit-at=0/0 max-limit=0/0
total-queue=default-small


script:

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

I have set the traf > 1 just to see if it works.

Another thing: I have level 1 routerOS, which allows only 1 queue, is that maybe why its not working?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7053
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: New to scripting in RouterOS

Mon Jul 30, 2007 11:08 am

if you are running on 2.9 then:
:local traf;
/queue simple
:for i from=1 to= 254 do = {
   :if ([/queue simple find target-addresses=("192.168.0." . $i)] != "") do={
      :set traf [/queue simple get [/queue simple find target-addresses=("192.168.0." . $i)] total-bytes]
      :if ($traf > 1) do = {
         /queue simple set [/queue simple find target-addresses=("192.168.0." . $i)] max-limit= 32000/64000
      }
   }
}
this should work!
 
ransom
newbie
Topic Author
Posts: 33
Joined: Sun Jul 29, 2007 12:26 pm

Re: New to scripting in RouterOS

Mon Jul 30, 2007 5:36 pm

Ok but with level 1 and 2.9 you can only have 1 simple queue which I already have for collecting the ip traffic needed in the script above. adding any more simple queues are not allowed... maybe time to get level 3?

:)

Oh and closing statements with the 3 }'s at the end, where the 3 start {'s ?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7053
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: New to scripting in RouterOS

Mon Jul 30, 2007 5:46 pm

Oh and closing statements with the 3 }'s at the end, where the 3 start {'s ?
1. :for loop ... do={
2. :if ([/queue .... do={
3 :if ($traf > 1) do = {
 
ransom
newbie
Topic Author
Posts: 33
Joined: Sun Jul 29, 2007 12:26 pm

Re: New to scripting in RouterOS

Mon Jul 30, 2007 8:15 pm

damn...sorry dude... I was replying on someone else' pc with very high res! { looked like [

Thanx for the patience
 
ransom
newbie
Topic Author
Posts: 33
Joined: Sun Jul 29, 2007 12:26 pm

Re: New to scripting in RouterOS

Mon Jul 30, 2007 8:47 pm

doesnt work... :? any ideas?

Who is online

Users browsing this forum: No registered users and 38 guests