ROS脚本集

多条动态ADSL接入控制脚本---脚本的风采

脚本如下:
:local assign-address
:local new-address
:local status
:local x
:set x 2
:for i from=1 to=$x do={
:set status [/interface get [/interface find name=("pppoe-out" . $i)] running]
:if ($status=true) do={
:set new-address [/ip address get [/ip address find dynamic=yes interface=("pppoe-out" . $i)] address]
:set new-address [:pick $new-address 0 ([:len $new-address] -3)]
:set assign-address [/ip address get [/ip address find dynamic=no interface=("pppoe-out" . $i)] address]
:set assign-address [:pick $assign-address 0 ([:len $assign-address] -3)]
:if ($assign-address != $new-address) do={ \
/ip address set [/ip address find comment=$i] address=$new-address network=$new-address broadcast=$new-address
/ip route set [/ip route find comment=$i] gateway=$new-address
}
}
}

----------------------------------------------
2.9系列ADSL端口影射回流脚本及新的问题--- 脚本的风采
:log info "Add-Nat: Sending Dynamic NAT update Begin"
:global ddns-interface [ /interface find type=pppoe-out ]
:global ddns-ip [ /ip address get [/ip address find interface=$ddns-interface] address ]
/ip firewall nat add chain=dstnat dst-address=$ddns-ip protocol=tcp dst-port=80 action=dst-nat to-addresses=192.168.10.251 to-ports=80 comment="WEB"

/ip firewall nat add chain=dstnat dst-address=$ddns-ip protocol=tcp dst-port=25 action=dst-nat to-addresses=192.168.10.251 to-ports=25 comment="SMTP"

/ip firewall nat add chain=dstnat dst-address=$ddns-ip protocol=tcp dst-port=21 action=dst-nat to-addresses=192.168.10.251 to-ports=21 comment="FTP"
:log info "Add-Nat: Sending Dynamic NAT update End Sucess!!!"

上面是自动把ADSL PPPOE的IP地址映射到192.168.10.251这台电脑上 后面是端口 地址和端口可以随便改然后

在SYSTEM SCRIPT下建立一个脚本名字add-nat

:log info "remove when ip is down"

/ip firewall nat remove WEB
/ip firewall nat remove SMTP
/ip firewall nat remove FTP


:log info "remove sucessful!!!"

在SYSTEM SCRIPT下建立一个脚本名字remove-nat

然后再TOOLS下的NETWATCH下建立一个监视网关的脚本UP

add-nat DOWN: remove-nat 就OK了 这样就可以象固定IP一样了

------------------------------------------------
快速建立PPPoe服务器脚本---脚本的风采
1、先要对ROS进行复位(以后你想再入什么再加了)
2、将脚本通过FTP复制进ROS
3、在ROS端输入im pppoe.rsc
这样就成功建立了你的ppoe服务器了

注:要先对脚本进行修改喔!以下是脚的样本
/ip address
add address=10.0.0.223/24 interface=ether1
#加入外网的IP:10.0.0.223地址在ether1的网卡上
/ip poo

l
add name=mypool ranges=192.168.0.2-192.168.0.254
#增加PPPoe服务的地址池
/ppp profile
add name="myserver" local-address=192.168.0.1 remote-address=mypool use-compression=default use-vj-compression=default \
use-encryption=default only-one=default change-tcp-mss=default rate-limit=512k/2048k comment=""
#增加PPPoe服务地址192.168.0.1,并设置上/下行的速度512k/2048k,要多个组就自己复制后,自己改了。
/ppp secret
add name=abc password=111 service=pppoe profile=myserver
#增加PPPoe用户的用户名aaa和密码111,所属的服务组为myserver,要多个用户就自己复制后,自己改了。
/ interface pppoe-server server
add service-name="mypppoe" interface=ether2 max-mtu=1480 max-mru=1480 \
authentication=pap,chap,mschap1,mschap2 keepalive-timeout=10 \
one-session-per-host=no max-sessions=0 default-profile=myserver \
disabled=no
#建立PPPoe服务
/ ip firewall nat
add chain=srcnat out-interface=ether1 action=masquerade comment="" disabled=no
#进行NAT地址转换,网卡是ether1
/ ip route
add dst-address=0.0.0.0/0 gateway=10.0.0.222 scope=255 target-scope=10 \
comment="added by setup" disabled=no
#设置网关10.0.0.222

-----------------------------------------------
按天数自动停号的脚本2.8版--脚本的风采
建立用户类型
/ppp profile
add name="normaluser" only-one=yes tx-bit-rate=100000 rx-bit-rate=600000
add name="freeuser" only-one=yes tx-bit-rate=100000 rx-bit-rate=600000

停号的脚本ROS2.8版
:local bz
#只停normaluesr普通用户
:foreach i in=[/ppp secret find profile=normaluser] do={
#已经disable的用户不进行减天数,再减就负数了
:if(![/ppp secret get $i disable]) do={
#取账号里的备注,备注记的就是剩下的天数
:set bz [/ppp secret get $i comment]
#将天数减1,减号两一定要留喔。否则不能运算,ROS脚本就是这么严格
:set bz ($bz - 1)
#再将天数写回备注
/ppp secret set $i comment=$bz
#如果备注的天数小于等于0就disbale停号
:if($bz<=0) do={/ppp secret disable $i}
}
}
#这是每天的备份
/system backup save name=autobackup
由2.8版脚本限制,比2.96版的少好多命令,只能就这样了。2.96版的可以做到备份的文件名是日

期,还可以将一些信息写入LOG日志。备注里除了记剩下天数外,再加别的备注也问题,脚本只修

改剩下的天数,不会改其它的备注的内容。

--------------------------------------------------------
二个网段的限速脚本-脚本风采
:for ccc from 1 to 254 do={/queue simple add name=(a . $ccc) dst-address=(192.168.1. . $ccc) limit-at=0/0 max-limit=2048/512000}

:for aaa from 1 to 254 do

={/queue simple add name=(b . $aaa) dst-address=(192.168.0. . $aaa) limit-at=0/0 max-limit=2048000/512000}

---------------------------------------------------------
脚本批量添加ros中PPPOE-SERVER拨号账户---脚本的风采
:for aaa from 1 to 254 do={/ ppp secret add name=(a . $aaa) service=pppoe caller-id="" password="123456" profile=PPPOE_IN remote-address=(192.168.100. . $aaa) routes="" limit-bytes-in=0 limit-bytes-out=0}

简单说明::for aaa from 1 to 254 do={/ ppp secret add name=(a . $aaa)………………(192.168.100. . $aaa)

这段截出来的文字中 红色的 均为变量,请不要调整。 其中蓝色的 代表名字 例如a那么产生的 名字就将为a1 a2 a12 a112 等等
有的时候为了方便 我们往往 使用001 002 010 100 这样的名字方便排列,所以 我们可以更懒一点

针对 1--9
:for aaa from 1 to 9 do={/ ppp secret add name=(a00 . $aaa) service=pppoe caller-id="" password="123456" profile=PPPOE_IN remote-address=(192.168.100. . $aaa) routes="" limit-bytes-in=0 limit-bytes-out=0}

针对10--99
:for aaa from 10 to 99 do={/ ppp secret add name=(a0 . $aaa) service=pppoe caller-id="" password="123456" profile=PPPOE_IN remote-address=(192.168.100. . $aaa) routes="" limit-bytes-in=0 limit-bytes-out=0}

针对100--254
:for aaa from 100 to 254 do={/ ppp secret add name=(a . $aaa) service=pppoe caller-id="" password="123456" profile=PPPOE_IN remote-address=(192.168.100. . $aaa) routes="" limit-bytes-in=0 limit-bytes-out=0}

---------------------------------------------------------------
限制脚本速度、线程、防ARP脚本-脚本风采
New Terminal 打开输入以下程序就OK了。记得把注释去掉,自己慢慢测试吧。。一下脚本全测试过,我所使用的版本为RouterOS Version:2.9.27
/ system script
;线程脚本
add name="a" source=":for aaa from 1 to 35 do={/ip firewall filter add \
chain=forward src-address=\(192.168.1. . \$aaa\) protocol=tcp \
connection-limit=50,32 action=drop}" \
policy=ftp,reboot,read,write,policy,test,winbox,password
------------------------------------------------------------------------------
;限速脚本
add name="A" source=":for aaa from 1 to 20 do={/queue simple add \
name=\(0_ . \$aaa\) dst-address=\(192.168.7. . \$aaa\) interface=ether1 \
limit-at=256000/64000 max-limit=512000/128000 burst-limit=1024000/256000 \
burst-threshold=512000/128000 burst-time=50s/50s }" \
policy=ftp,reboot,read,write,policy,test,winbox,password
------------------------------------------------------------------------------
;防ARP,自动COPY
add name="IP" source=":foreach i in=\[/ip arp find dynamic=yes \] do={/ip arp \
add copy-from=\$i}\n\n" \
policy=ftp

,reboot,read,write,policy,test,winbox,password
------------------------------------------------------------------------------
限制速度脚本
/system/script
:for aaa from 5 to 20 do={/queue simple add name=(A . $aaa) dst-address=(192.168.1. . $aaa) interface=all limit-at=1000000/64000 max-limit=1000000/128000 burst-limit=1024000/256000 burst-threshold=512000/128000 burst-time=50s/50s }

-------------------------------------------------------------------
建多个防火墙规则.取bandwidth测试值脚本----脚本的风采
创造多个防火墙规则
在firewall里输入多个规则,地址从1.1.1.1直到1.1.1.100 (例子中的e是变量)

:for e from 1 to 100 do={
/ip firewall rule input add \
src-address=(1.1.1. . $e)\
src-netmask=255.255.255.255
}

获得bandwidth测试值
这个例子表示如何获得bandwidth测试命令的结果。同样的例子使用了全局变量,其他脚本可能同时在命

令中获得当前TX的数据。

/system script add name=bandtest source={
:global i
/tool bandwidth-test 1.1.1.1 \
direction=transmit \
duration=14s \
do={
:if ($status="running") do={
:set i $tx-current
}
}
}

------------------------------------------------------------
批量添加单机限速脚本---脚本的风采
:for yxcs from 2 to 254 do={
/queue simple
add name=("第" . $yxcs . "号机") dst-address=("192.168.1." . $yxcs . "/32") max-limit=1024000/1024000
}
#上脚本作用:批量添加单机限速IP=2 到254
=============================
将以上代码复制到sys script中新建的脚本文件中,执行。

-------------------------------------------------------------
用脚本绑定ip--mac例子---小脚本大功效
:foreach i in [/ip arp find dynamic yes ] do={/ip arp add copy-from $i}

把这个建到一个system ->script里面,run一下就OK了,可以实现对在线机器的MAC与IP的绑定。


相关文档
最新文档