接到任务,除周末和节假日外,晚上23:40分至第二天早上06:00断掉学生宿舍网络
学校网络结构如下:每栋学生宿舍楼有cisco3560X汇聚交换机一台,交换机上千兆单模光口4个,其中1口二层透传至移动机房华为9306,1口三层路由至校园网络可访问学校数据中心,1口二层trunk至校园网络监控中心
实施断网,就是要断开连接移动核心交换机的gig 1/1口连接,或通过ACL阻塞所有该接口通行的流量。
动手
1、开始想的办法是做基于时间的ACL,时间服务器和整网的设备时间同步是必须的,具体配置如下:
ntp server192.168.200.200//做好时钟同步,否则交换机重启后时间会指向00:00分。
time-rangeduanwang//定义断网的时间范围
absolute start 19:16 19 March 2012 end 19:16 15July 2012
periodic Sunday 23:40 to 23:59
periodic Monday 0:01 to 6:00
periodic Monday 23:40 to 23:59
periodic Tuesday 0:01 to 6:00
periodic Tuesday 23:40 to 23:59
periodic Wednesday 0:01 to 6:00
periodic Wednesday 23:40 to 23:59
periodic Thursday 0:01 to 6:00
periodic Thursday 23:40 to 23:59
periodic Friday 0:01 to 6:00
access-list 110 deny ip anyany time-rangeduanwang//基于时间的访问控制列表
考虑把它应用在3560X gig1/1接口IN方向上(连接华为S9306的光口),应用后未起作用,分析原因该接口是二层接口,透传PPPOE报文至上层设备,接口为trunk,802.1Q,IPACL在二层接口上不起作用,而且学生上网的流量都是PPPOE封装的报文,普通IP ACL无法识别。
2、考虑用MAC ACL,拒绝任意的MAC地址应该就能够实现彻底的断网,配置如下:
mac access-list extened a
deny any any
interface gig 1/1
mac access-group a in
配置后流量完全配阻断,达到预期效果,但缺陷是MACACL不支持基于时间段的做法,也就意味着每天深更半夜都要配一遍,所以还要继续专研.
3、考虑用批处理+VBS编写脚本,然后在一台服务器上设置计划任务,每天到了时间自动运行脚本通过telnet配置设备。
批处理文件 aaa.bat内容如下:
starttelnet.exe//运行telnet.exe程序
rem batch telnet
cscript //nologoaaa.VBS//在telnet.exe程序中执行aaa.vbs脚本
aaa.vbs脚本内容:
setsh=WScript.CreateObject("WScript.Shell")
WScript.Sleep1000
sh.SendKeys "open172.31.254.2{ENTER}"
WScript.Sleep1000
sh.SendKeys "用户名{ENTER}"
WScript.Sleep1000
sh.SendKeys "密码{ENTER}"
WScript.Sleep1000
sh.SendKeys "telnet172.31.8.2{ENTER}"
WScript.Sleep1000
sh.SendKeys "用户名{ENTER}"
WScript.Sleep1000
sh.SendKeys"密码{ENTER}"
WScript.Sleep 1000
sh.SendKeys "conf t{ENTER}"
WScript.Sleep 1000
sh.SendKeys "inter gig 1/1{ENTER}"
WScript.Sleep 1000
sh.SendKeys "mac access-group a in{ENTER}"
WScript.Sleep 1000
sh.SendKeys "end{ENTER}"
WScript.Sleep 1000
sh.SendKeys"exit{ENTER}"
sh.SendKeys "telnet172.31.16.2{ENTER}"
WScript.Sleep1000
sh.SendKeys "用户名{ENTER}"
WScript.Sleep1000
sh.SendKeys"密码{ENTER}"
WScript.Sleep 1000
sh.SendKeys "conf t{ENTER}"
WScript.Sleep 1000
sh.SendKeys "inter gig 1/1{ENTER}"
WScript.Sleep 1000
sh.SendKeys "mac access-group a in{ENTER}"
WScript.Sleep 1000
sh.SendKeys "end{ENTER}"
WScript.Sleep 1000
sh.SendKeys "exit{ENTER}"
sh.SendKeys "telnet172.31.17.2{ENTER}"
WScript.Sleep1000
sh.SendKeys "用户名{ENTER}"
WScript.Sleep1000
sh.SendKeys"密码{ENTER}"
WScript.Sleep 1000
sh.SendKeys "conf t{ENTER}"
WScript.Sleep 1000
sh.SendKeys "inter gig 1/1{ENTER}"
WScript.Sleep 1000
sh.SendKeys "mac access-group a in{ENTER}"
WScript.Sleep 1000
sh.SendKeys "end{ENTER}"
WScript.Sleep 1000
sh.SendKeys "exit{ENTER}"
sh.SendKeys "telnet172.31.18.2{ENTER}"
WScript.Sleep1000
sh.SendKeys "用户名{ENTER}"
WScript.Sleep1000
sh.SendKeys"密码{ENTER}"
WScript.Sleep 1000
sh.SendKeys "conf t{ENTER}"
WScript.Sleep 1000
sh.SendKeys "inter gig 1/1{ENTER}"
WScript.Sleep 1000
sh.SendKeys "mac access-group a in{ENTER}"
WScript.Sleep 1000
sh.SendKeys "end{ENTER}"
WScript.Sleep 1000
sh.SendKeys "exit{ENTER}"
sh.SendKeys "telnet172.31.20.2{ENTER}"
WScript.Sleep1000
sh.SendKeys "用户名{ENTER}"
WScript.Sleep1000
sh.SendKeys"密码{ENTER}"
WScript.Sleep 1000
sh.SendKeys "conf t{ENTER}"
WScript.Sleep 1000
sh.SendKeys "inter gig 1/1{ENTER}"
WScript.Sleep 1000
sh.SendKeys "mac access-group a in{ENTER}"
WScript.Sleep 1000
sh.SendKeys "end{ENTER}"
WScript.Sleep 1000
sh.SendKeys "exit{ENTER}"
sh.SendKeys "telnet172.31.21.2{ENTER}"
WScript.Sleep1000
sh.SendKeys "用户名{ENTER}"
WScript.Sleep1000
sh.SendKeys"密码{ENTER}"
WScript.Sleep 1000
sh.SendKeys "conf t{ENTER}"
WScript.Sleep 1000
sh.SendKeys "inter gig 1/1{ENTER}"
WScript.Sleep 1000
sh.SendKeys "mac access-group a in{ENTER}"
WScript.Sleep 1000
sh.SendKeys "end{ENTER}"
WScript.Sleep 1000
sh.SendKeys "exit{ENTER}"
sh.SendKeys "telnet172.31.22.2{ENTER}"
WScript.Sleep1000
sh.SendKeys "用户名{ENTER}"
WScript.Sleep1000
sh.SendKeys"密码{ENTER}"
WScript.Sleep 1000
sh.SendKeys "conf t{ENTER}"
WScript.Sleep 1000
sh.SendKeys "inter gig 1/1{ENTER}"
WScript.Sleep 1000
sh.SendKeys "mac access-group a in{ENTER}"
WScript.Sleep 1000
sh.SendKeys "end{ENTER}"
WScript.Sleep 1000
sh.SendKeys "exit{ENTER}"
sh.SendKeys "telnet192.168.16.254{ENTER}"
WScript.Sleep1000
sh.SendKeys "用户名{ENTER}"
WScript.Sleep1000
sh.SendKeys"密码{ENTER}"
WScript.Sleep 1000
sh.SendKeys "conf t{ENTER}"
WScript.Sleep 1000
sh.SendKeys "inter gig 1/1{ENTER}"
WScript.Sleep 1000
sh.SendKeys "mac access-group a in{ENTER}"
WScript.Sleep 1000
sh.SendKeys "end{ENTER}"
WScript.Sleep 1000
sh.SendKeys "exit{ENTER}"
WScript.Sleep 1000
sh.SendKeys "exit{ENTER}"
此后在一台服务器上设定了计划任务,到点运行aaa.bat批处理程序即可调用telnet.exe程序及vbs脚本实现设备的自动配置,准时断网。