MikroTik RouterOS获取在线终端和在线IP总数并自动对IP做限速

2019-07-0214:58:32 发表评论 104 views
阿里云首台5折

1、将在线IP自动添加到地址列表

MikroTik RouterOS获取在线终端和在线IP总数并自动对IP做限速 MikroTik RouterOS获取在线终端和在线IP总数并自动对IP做限速 MikroTik RouterOS获取在线终端和在线IP总数并自动对IP做限速 MikroTik RouterOS获取在线终端和在线IP总数并自动对IP做限速

 

2、实时检测在线IP数

MikroTik RouterOS获取在线终端和在线IP总数并自动对IP做限速

MikroTik RouterOS获取在线终端和在线IP总数并自动对IP做限速

MikroTik RouterOS获取在线终端和在线IP总数并自动对IP做限速

 

代码 :local s 0 :foreach i in=[/ip firewall address-list find list=Online] do={:set s ($s+1)} :log warning ("当前" . $s . "个IP在线")  

运行脚本

/system scheduler

add comment=tongji interval=3m name="\CD\B3\BC\C6" on-event="#\D7\EE\B4\F3\D1\AD\

\BB\B7\B4\CE\CA\FD\r\

\n:global rmaxlimit 5000\r\

\n:global r 0\r\

\n:global rn\r\

\n:global rs\r\

\n:global ravg\r\

\n:global rmax\r\

\n:if ([:len \$ravg] = 0) do={\r\

\n:set ravg 0\r\

\n:global rn 0\r\

\n:global rs 0\r\

\n:global rmax 0}\r\

\n:if (\$rs = \$rmaxlimit) do={\r\

\n:global rn \$ravg\r\

\n:global rs 1}\r\

\n:foreach b in=[/ip firewall add find list=\"Online\"] do={:set r (\$r+1)}\

\r\

\n:if (\$rmax < \$r) do={:set rmax \$r}\r\

\n:set rs (\$rs+1)\r\

\n:set rn (\$rn+\$r)\r\

\n:global ravg (\$rn / \$rs)\r\

\n:log warning (\"\B5\B1\C7\B0\D4\DA\CF\DF\BF\CD\BB\A7\BB\FA\" . \$r . \"\CC\

\A8,\C6\BD\BE\F9\D4\DA\CF\DF\BF\CD\BB\A7\BB\FA\" . \$ravg . \",\D7\EE\B8\DF\

\D4\DA\CF\DF\C0\FA\CA\B7\" . \$rmax . \"\CC\A8,\B5\B1\C7\B0\CD\B3\BC\C6\B4\

\CE\CA\FD\" . \$rs . \"\A1\A3\")" policy=\

reboot,read,write,policy,test,password,sniff,sensitive start-time=startup

代码 #最大循环次数
:global rmaxlimit 5000
:global r 0
:global rn
:global rs
:global ravg
:global rmax
:if ([:len $ravg] = 0) do={
:set ravg 0
:global rn 0
:global rs 0
:global rmax 0}
:if ($rs = $rmaxlimit) do={
:global rn $ravg
:global rs 1}
:foreach b in=[/ip firewall add find list="Online"] do={:set r ($r+1)}
:if ($rmax < $r) do={:set rmax $r}
:set rs ($rs+1)
:set rn ($rn+$r)
:global ravg ($rn / $rs)
:log warning ("当前在线客户机" . $r . "台,平均在线客户机" . $ravg . ",最高在线历史" . $rmax . "台,当前统计次数" . $rs . "。")

3、自动对IP做限速

MikroTik RouterOS获取在线终端和在线IP总数并自动对IP做限速

MikroTik RouterOS获取在线终端和在线IP总数并自动对IP做限速

MikroTik RouterOS获取在线终端和在线IP总数并自动对IP做限速

 

代码 :local s 0 :foreach i in=[/ip firewall address-list find list=Online] do={:set s ($s+1)} :foreach i in=[/ip firewall address-list find list=Online] do={:local ip 0;set ip [:ip firewall address-list get $i address];if (/queue simple get [/queue simple find name=$ip] = "") do={:queue simple add max-limit=20M/6M name=$ip target=$ip;log warning ($ip."限速upload:20M,download:6M")}}
  • NAS技术交流
  • 扫一扫入裙
  • weinxin
  • 软路由技术讨论
  • 扫一扫入裙
  • weinxin
阿里云首台5折

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: