国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)管 > 路由交換 > 正文

Mikrotik ROS腳本語法入門

2020-07-23 18:49:16
字體:
來源:轉載
供稿:網(wǎng)友

ROS也可稱為是Route Operation System,意為"軟件路由器".

一般認為用普通PC安裝一套專用的路由器程序組成的系統(tǒng)稱為軟件路由器,PC電腦+免費的軟件=專業(yè)的軟件路由器

ROS 腳本 注解
四種變量
global - 定義全局變量, 可以要所有的 腳本 中調(diào)用共享
local - 定義本地變量,只能在其所要的 腳本 下調(diào)用,不能被其它 腳本 共享
loop index variables - 定義在for或foreach里的索引號變量
monitor variables - 監(jiān)視變量
ROS算術操作
- 負號;相減。
! 邏輯非。
/ 相除。
. 連接。兩個符串的連接,添加元素到列表
^ 異或(XOR)
~ 取反
* 相剩
& 與(AND)
&&邏輯與
+ 相加
< 小于
<<向左位移
<=小于等于
> 大于
>=大于等于
>>向右位移
| 或
||邏輯或
ROS說明書里的例子:
計算順序
[admin@MikroTik]> :put (10+1-6*2=11-12=2+(-3)=-1)
false
[admin@MikroTik]> :put (10+1-6*2=11-12=(2+(-3)=-1))
true
邏輯非
[admin@MikroTik]> :put (!true)
false
[admin@MikroTik]> :put (!(2>3))
true
數(shù)位取反
[admin@MikroTik]> :put (~255.255.0.0)
0.0.255.255
加法
[admin@MikroTik]> :put (3ms + 5s)
00:00:05.003
[admin@MikroTik]> :put (10.0.0.15 + 0.0.10.0)
cannot add ip address to ip address
[admin@MikroTik]> :put (10.0.0.15 + 10)
10.0.0.25
減法
[admin@MikroTik]> :put (15 - 10)
5
[admin@MikroTik]> :put (10.0.0.15 - 10.0.0.3)
12
[admin@MikroTik]> :put (10.0.0.15 - 12)
10.0.0.3
[admin@MikroTik]> :put (15h - 2s)
14:59:58
乘法
[admin@MikroTik]> :put (12s * 4)
00:00:48
[admin@MikroTik]> :put (-5 * -2)
10
除法
[admin@MikroTik]> :put (10s / 3)
00:00:03.333
[admin@MikroTik]> :put (5 / 2)
2
[admin@MikroTik]> :put (0:0.10 / 3)
00:00:02
比較
[admin@MikroTik]> :put (10.0.2.3<=2.0.3.10)
false
[admin@MikroTik]> :put (100000s>27h)
true
[admin@MikroTik]> :put (60s,1d!=1m,3600s)
true
[admin@MikroTik]> :put (bridge=routing)
false
[admin@MikroTik]> :put (yes=false)
false
[admin@MikroTik]> :put (true=aye)
false
邏輯與 AND, 邏輯或 OR
[admin@MikroTik]> :put ((yes && yes) || (yes && no))
true
[admin@MikroTik]> :put ((no || no) && (no || yes))
false
數(shù)位與AND, 或OR, 異或XOR
[admin@MikroTik]> :put (10.16.0.134 & ~255.255.255.0)
0.0.0.134
位移操作
[admin@MikroTik]> :put (~((0.0.0.1 << 7) - 1))
255.255.255.128
連接操作
[admin@MikroTik]> :put (1 . 3)
13
[admin@MikroTik]> :put (1,2 . 3)
1,2,3
[admin@MikroTik]> :put (1 . 3,4)
13,4
[admin@MikroTik]> :put (1,2 . 3,4)
1,2,3,4
[admin@MikroTik]> :put ((1 . 3) + 1)
14
[admin@MikroTik]> :seta "It's "
[admin@MikroTik]> :put ($a . OK)
It's OK
ROS 腳本 保留字
beep execute global list pick time toip typeof
delay find if local put toarray tonum while
do for led log resolve tobool tostr
environment foreach len nothing set toid totime
:beep length=2s frequency=10000
產(chǎn)生2秒10kHz的音頻
length缺省值為100ms
frequency缺省值為1000Hz
:set a "/int dis lan/n/int dis wan"
:execute $a
執(zhí)行多條命令,例子里執(zhí)行了兩條命令。/n是換行
:global
定義全局變量
:list interface
顯示相關命令。顯示當前目錄及子目錄下有關interface的命令
:pick
取字符串或數(shù)組的某一斷。字符串(數(shù)組)的第一個為0。
[admin@MikroTik]>:put [:pick "I love you" 2 6]
love
:time
執(zhí)行命令所需的時間
[admin@MikroTik]> :put [:time [:resole www.sina.com.cn]]
00:00:00.006
執(zhí)行解析www.sina.com.cn這個域名所需的時間
toip toarray tonum tobool tostr toid totime
轉換值類型
:delay 3
延時3秒,缺省為1秒
:find
查找字符串或數(shù)組中第一個出現(xiàn)查找內(nèi)容的位置
[admin@MikroTik]>:put [:find abcdcba cd]
2
[admin@MikroTik]>:put [:find "1,2,3,4,3,2,1" 2]
1
:put
輸出到屏幕上,上面就很多例子了。
:if
條件選擇
[admin@MikroTik]>:if(1<2) do={:put true}
true
如果條件為真,執(zhí)行do={}里面的命令
[admin@MikroTik]>:if(1>2) do={:put true} else={:put flase}
flase
如果條件為真,執(zhí)行do={}里面的命令,否則執(zhí)行else={}里有命令
:local
定義本地變量
:while
條件為真時循環(huán)執(zhí)行do={}里的 腳本 命令
[admin@MikroTik]>:set i 0;:while($i<5) do={:put $i;:set i ($i+1)}
0
1
2
3
4
5
:for
循環(huán)執(zhí)行do={}里的 腳本 命令
:for i from=1 to=100 step=30 do={:put $i}
1
31
61
91
:foreach
在集合(數(shù)組)里循環(huán)執(zhí)行do={}里的 腳本 命令
:foreach i in=[/interface find type=ether] do={:put [/interface get $i name]}
ether1
ether2
ether3
ether4
在[/interface find type=ether]的集合(類型為ether的interface ID)循環(huán)輸出
interface的名稱。我這時有四張網(wǎng)卡
:log 日志類型 日志內(nèi)容
寫文本到日志(script log)
類型在/system logging里可以找到
:log info "系統(tǒng)信息"
到LOG里查查運行結果吧
:resolve
解析域名的IP地址
[admin@MikroTik] > :put [:resolve www.sina.com.cn]
61.172.201.240
:environment print
顯示所有變量及其值
:len
字符串或數(shù)組的長度
[admin@MikroTik] > :put [:len hello]
5
[admin@MikroTik] > :put [:len "1,2,23,65,54,6"]
6
:nothing
空值。nothing不等0,不等于空字符""
:find abc a的結果是0
:find abc d的結果是nothing
:set
賦值
[admin@MikroTik] > :set a test
將abc字符賦給變量a
[admin@MikroTik] > :put $a
test
[admin@MikroTik] > :put a
a
引用變量的值要在變量前面加$

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 渝北区| 乐安县| 大宁县| 宝应县| 盐边县| 天门市| 太仆寺旗| 晋中市| 青河县| 临颍县| 陆河县| 隆安县| 怀安县| 尚志市| 嘉义市| 南康市| 天长市| 凤台县| 临安市| 台前县| 墨玉县| 蓬溪县| 德保县| 红桥区| 万州区| 大新县| 沙湾县| 苏尼特右旗| 上林县| 夹江县| 万源市| 务川| 花垣县| 延长县| 清徐县| 莱芜市| 晋城| 永顺县| 隆林| 东阳市| 吴川市|