DHCP环境下的WEB到期提醒,MXSO老大脚本修改了一点.
我的DHCP给用户不变的IP地址.再做的ARP IP MAC绑定.限制非法用户.以下做了点修改.适合自已的环境.再次感谢mxso老大:local 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= do={
#/
:set Ccomment ;: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 ;: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 (!) do={disable $i;/ip arp disable
#/ip firewall address-list remove
#/ip firewall address-list remove
}} else={:if () do={enable $i}}
#提前几天通知用户 如果该用户项不是block的则设定.没设address-list表的.设定.
:if (($CToday-3) < $Today) do={
#dhcp用户block没设置.和用户address-list=""
#:if ([:len block-access]]=0) do={
#set $i block-access=yes
#set block-access=yes
#:log info ("1")
#}
:if (!="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") 这个是DHCP的?
能自动清除SRC2的地址么? 这脚本怎么我看起来不会用的样子?楼主请贴出使用说明... 支持。。。。顶啊,,早想到了没动手,,高人,谢分享
页:
[1]