Ros检测WAN口断网脚本

该脚本会自动检测WAN口是否断网状态
如果WAN口处于断网状态则自动把当前时间写入全局断网时间变量(即$WANDownNetworkDate),并自动关闭网络联通Down状态检测的定时任务,然后打开网络联通Up状态检测的定时任务
如果WAN口处于联网状态则自动把当前连网成功的时间写入全局联网时间变量(即$WANUpNetworkDate),并自动关闭网络联通状态Up状态检测的定时任务,然后打开网络联通Down状态检测的定时任务

  • 先新建两个定时任务
/system scheduler

add interval=3s name="Auto Check WAN Down" on-event=\
    ":execute script=\"Auto Check WAN Down Script\"" policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
    start-time=startup

add disabled=yes interval=3s name="Auto Check WAN Up" on-event=\
    ":execute script=\"Auto Check WAN Up Script\"" policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
    start-time=startup
  • 导入检测脚本
/system script

add dont-require-permissions=no name="Auto Check WAN Down Script" owner=admin \
    policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
    source="{\r\
    \n    :local date [/system clock get date]\r\
    \n    :local time [/system clock get time]\r\
    \n    :global WANDownNetworkDate\r\
    \n    :global WANUpNetworkDate\r\
    \n    :global GooglePingArgValue\r\
    \n    :if (:put ([/ping 8.8.4.4 count=1] = 0)) do= {\r\
    \n        :set WANDownNetworkDate \"\$date \$time\"\r\
    \n        :set WANUpNetworkDate 0\r\
    \n        :system scheduler set \"Auto Check WAN Up\" disabled=no\r\
    \n        :system scheduler set \"Auto Check WAN Down\" disabled=yes\r\
    \n        :log error \"WAN Ineterface Is TimeOut!   NowTime is \$date \$ti\
    me\"\r\
    \n        \r\
    \n    }\r\
    \n}"


add dont-require-permissions=no name="Auto Check WAN Up Script" owner=admin \
    policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
    source="{\r\
    \n    :local date [/system clock get date]\r\
    \n    :local time [/system clock get time]\r\
    \n    :global WANDownNetworkDate\r\
    \n    :global WANUpNetworkDate\r\
    \n    :global GooglePingArgValue\r\
    \n    :if (:put ([/ping 8.8.4.4 count=1] > 0)) do= {\r\
    \n        :set WANUpNetworkDate \"\$date \$time\"\r\
    \n        :set WANDownNetworkDate 0\r\
    \n        :system scheduler set \"Auto Check WAN Up\" disabled=yes\r\
    \n        :system scheduler set \"Auto Check WAN Down\" disabled=no\r\
    \n        :log warn \"WAN Ineterface Is Up!   NowTime is \$date \$time\"\r\
    \n    }\r\
    \n}"
  • 定时任务视图

Ros检测WAN口断网脚本

  • 脚本视图

Ros检测WAN口断网脚本

  • 全局变量视图

Ros检测WAN口断网脚本

当对 Ether1 进行 Disabled 操作时

Ros检测WAN口断网脚本

Ros检测WAN口断网脚本

Ros检测WAN口断网脚本

Ros检测WAN口断网脚本

赞(0)

评论 1

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #-19

    Hello there! I could have sworn I’ve visited this website before but after going through many of the posts I realized it’s new to me. Anyways, I’m definitely delighted I found it and I’ll be book-marking it and checking back regularly!

    Lorna Lucido7个月前 (02-21)Reply