24.11.2014 Views

General Information

General Information

General Information

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Local<br />

Variables<br />

g1=this is global variable<br />

l1=this is local variable<br />

counter=2<br />

[admin@MikroTik] ><br />

for - this action takes one argument, the name of the loop variable. It has also four parameters,<br />

from, to, step and do. First two parameters indicate the borders for the loop counter. The interval<br />

includes these two values as well. The third one specifies the step of decrement (or increment).<br />

And, finally, the do statement holds console commands to repeat.<br />

[admin@MikroTik] > :for i from=1 to=100 step=37 do={:put ($i . " - " . 1000/$i)}<br />

1 - 1000<br />

38 - 26<br />

75 - 13<br />

[admin@MikroTik] ><br />

foreach - this action takes one argument, the name of the loop variable. It has also two parameters,<br />

in and do. The in argument is treated as a list with each value assigned to the loop variable, and do<br />

statement executed for this value. If in value is not a list then do statement is executed only once. in<br />

case in value is empty, do statement is not executed at all. This way it is optimized to work with<br />

find command, which returns lists of internal numbers, and may return an empty list or just one<br />

internal number. This example prints all ethernet interfaces, each followed by all addresses that are<br />

assigned to it:<br />

[admin@MikroTik] > :foreach i in=[/interface find type=ether ] do={<br />

{... :put [/interface get $i name]<br />

{... :foreach j in=[/ip address find interface=$i] do={<br />

{{... :put [/ip address get $j address]<br />

{{... }<br />

{... }<br />

ether1<br />

ether2<br />

10.0.0.65/24<br />

[admin@MikroTik] ><br />

if - this action takes one argument, a logical condition, id est an expression which must return a<br />

boolean value. It has also two parameters, do and else. If the logical condition is evaluated to true<br />

then the part after the do parameter is executed, otherwise the else part takes place. Note, that else<br />

part is optional.<br />

[admin@MikroTik] > :if (yes) do={:put yes} else={:put no}<br />

true<br />

[admin@MikroTik] > :if ([/ping 10.0.0.1 count=1] = 0) do {:put "gw unreachable"}<br />

10.0.0.1 pong timeout<br />

1 packets transmitted, 0 packets received, 100% packet loss<br />

gw<br />

unreachable<br />

[admin@MikroTik] ><br />

log - this action adds an entry to the system logs. It has two parameters, message which contains the<br />

string needed to be added and facility which, in turn, specifies by which logging facility the<br />

message should be logged. The facility parameter defaults to System-Info<br />

[admin@MikroTik] > :log facility=Firewall-Log message="Very Good \<br />

\... Thing happened. We have received our first packet!"<br />

[admin@MikroTik] ><br />

put - this action takes one argument, which it echoes to console.<br />

resolve - this action takes one argument, a DNS name and resolves it to the IP address of the host.<br />

You have to configure DNS settings on the router (/ip dns submenu) prior to using this action.<br />

[admin@MikroTik] ip route> /ip dns set primary-dns=159.148.60.2<br />

[admin@MikroTik] ip route> :put [:resolve www.example.com]<br />

192.0.34.166<br />

Page 530 of 568<br />

Copyright 1999-2005, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.<br />

Other trademarks and registred trademarks mentioned herein are properties of their respective owners.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!