找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 5760|回复: 3

[脚本] DHCP环境下的WEB到期提醒,MXSO老大脚本修改了一点.

[复制链接]
发表于 2011-11-27 19:39:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
我的DHCP给用户不变的IP地址.再做的ARP IP MAC绑定.限制非法用户.以下做了点修改.适合自已的环境.再次感谢mxso老大
:local Date [/system clock get date];:local Year ([:pick $Date 7 11]-1)
:local Month ([:find jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec [:pick $Date 0 3]])
:local Day [:pick $Date 4 6];:if ([:pick $Date 4 5] = 0) do={:set Day [:pick $Date 5 6]};:set Day ($Day-1)
:local leapyear 0,31,59,90,120,151,181,212,243,273,304,334,0,31,60,91,121,152,182,213,244,274,305,335
:global Today ($Year*365+$Year/4);:if (($Year-$Year/4*4) != 3) do={:set Today ($Today+[:pick $leapyear $Month]+$Day)} else={:set Today ($Today+[:pick $leapyear ($Month+12)]+$Day)}
:local usip;:local Ccomment;:local lc;:local rc;:local Exp;:local js;:local pcl;:local CYear;:local CMonth;:local CDay;:local CToday

#利用公元天数计算今天是星期几,0代表星期日
:global Week ($Today-$Today/7*7)
:log info ("今天是星期" . $Week)

#scheduler处理开始

#PPP处理开始
/ip dhcp-server lease
:foreach i in=[find comment!=""] do={
#/
:set Ccomment [get $i comment];:set lc [:find $Ccomment "["];:set rc [:find $Ccomment "]"]
:if ([:typeof $lc]="num" && [:typeof $rc]="num" && $lc<$rc) do={
#if1开始
:set Exp [:pick $Ccomment ($lc+1) $rc];:set js 0;:set CToday 0
:if ([:pick $Exp 0 1]!="+" && [:len $Exp]>7 && [:typeof [:tonum [:pick $Exp 0 8]]]="num") do={
:set usip [get $i address];:set CYear ([:pick $Exp 0 4]-1);:set CToday ($CYear*365+$CYear /4)
:set CMonth [:pick $Exp 4 6];:if ([:pick $Exp 4 5] = 0) do={ :set CMonth [:pick $Exp 5 6]};:set CMonth ($CMonth-1)
:set CDay [:pick $Exp 6 8];:if ([:pick $Exp 6 7] = 0) do={ :set CDay [:pick $Exp 7 8]};:set CDay ($CDay-1)
:if (($CYear-$CYear/4*4) != 3) do={:set CToday ($CToday+[:pick $leapyear $CMonth]+$CDay)} else={:set CToday ($CToday+[:pick $leapyear ($CMonth+12)])}}
:set pcl [:find $Exp "+"];:if ([:typeof $pcl]="num" && ($pcl>7 || $pcl=0) && ([:len $Exp]-1)>$pcl) do={
:if ($pcl = 0) do={:set CToday $Today;:set CYear ($Year+1);:set CMonth ($Month+1);:set CDay ($Day+1)
:if ([:len $CMonth]<2) do={:set CMonth ("0" . $CMonth)};:if ([:len $CDay]<2) do={:set CDay ("0" . $CDay)}
set $i comment=([:pick $Ccomment 0 $lc] . "[" .($CYear . $CMonth . $CDay) . [:pick $Exp $pcl [:len $Exp]] . "]" . [:pick $Ccomment ($rc+1) [:len $Ccomment]])}
:while ([:typeof [:find $Exp "+"]]="num") do={
:set Exp [:pick $Exp ($pcl+1) [:len $Exp]];:set pcl [:find $Exp "+"];:if ([:typeof $pcl]!="num") do={:set pcl [:len $Exp]}
:set js ($js+[:tonum [:pick $Exp 0 $pcl]])};:set CToday ($CToday+$js)}
#例子1:到期用户禁用IP-ARP用户绑定,禁用dhcp-server lease 项,其它未到期用户禁用的.则启用,#PPP处理结束
:if ($CToday < $Today) do={:if (![get $i disabled ]) do={disable $i;/ip arp disable [/ip arp find address=$usip]
#/ip firewall address-list remove [find list=ExpAuto_allow]
#/ip firewall address-list remove [find list=ExpAuto_expired]
}} else={:if ([get $i disabled ]) do={enable $i}}
#提前几天通知用户 如果该用户项不是block的则设定.没设address-list表的.设定.
:if (($CToday-3) < $Today) do={
#dhcp用户block没设置.和用户address-list=""
#:if ([:len [get [find address=192.168.10.114] block-access]]=0) do={
#set $i block-access=yes
#set [find address=192.168.10.114] block-access=yes
#:log info ("1")
#}
   :if ([get $i address-list]!="ExpAuto_expired") do={
:log info ("set dhcp-server address-list=ExpAuto_expired")
set $i address-list="ExpAuto_expired"
}
}
:log info ($usip)
#if1结束
}
#/
}

:log info ("testok")
routeros
发表于 2011-11-27 21:41:32 | 显示全部楼层
这个是DHCP的?
能自动清除SRC2的地址么?

点评

自动的,设置timeout就好了,,  发表于 2011-11-28 19:59
routeros
回复

使用道具 举报

发表于 2011-11-27 21:42:45 | 显示全部楼层
这脚本怎么我看起来不会用的样子?楼主请贴出使用说明...
routeros
回复

使用道具 举报

发表于 2011-11-28 19:58:53 | 显示全部楼层
支持。。。。顶啊,,早想到了没动手,,高人,谢分享
routeros
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|软路由 ( 渝ICP备15001194号-1|渝公网安备 50011602500124号 )

GMT+8, 2024-12-22 21:56 , Processed in 0.047333 second(s), 5 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表