找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3236|回复: 4

[脚本] 谁知道DHCP环境(非PPPOE拔号上网坏境)怎么做WEB到期提前通知呢?

[复制链接]
发表于 2012-9-13 11:24:38 | 显示全部楼层 |阅读模式

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

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

×
谁知道DHCP环境怎么做到期提前通知呢?,在本坛找到一个相关贴子,不过他的脚本在3.30不能运行,我贴上脚本,麻烦知道的告知下

: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.1.1] block-access]]=0) do={
#set $i block-access=yes
#set [find address=192.168.1.1] 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
 楼主| 发表于 2012-9-13 11:26:53 | 显示全部楼层
这脚本我放在3.30下不能运行,
routeros
回复

使用道具 举报

 楼主| 发表于 2012-9-13 16:47:44 | 显示全部楼层
说说吧..............
routeros
回复

使用道具 举报

 楼主| 发表于 2012-9-13 23:01:13 | 显示全部楼层
是不是我要求太高了?
routeros
回复

使用道具 举报

 楼主| 发表于 2012-9-15 10:54:51 | 显示全部楼层
没人想要做就算了
routeros
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-29 19:20 , Processed in 0.054614 second(s), 4 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2023 Discuz! Team.

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