最近在ZJJ出差,学校里的网络非常不稳定,分分钟掉线,华为售后说是有AR P攻 击,需要把所有接入交换机配置防止ARP攻击,几百条交换机一个一个配,会死,于是网上找了批量配置脚本,但很多都是复制粘贴的,全都是备份交换机配置的那篇文章,我是要写入配置信息,只能自己引用部分网上的,自己发挥一部分,下面说重点。
我用的是SCRT,有一个录制脚本功能,最好是先录制脚本,这样不会出错,然后把交换机地址添加进去,交换机地址另存为TXT文本格式,一行一个,密码我们是统一的,脚本如下。
#$language = "VBScript"
#$interface = "1.0"
Sub Main
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso,file1,line,str1,params
Set fso = CreateObject("Scripting.FileSystemObject")
Set file1 = fso.OpenTextFile("C:\Users\TSGLYW\Desktop\ip.txt",Forreading, False)
crt.Screen.Synchronous = True
DO While file1.AtEndOfStream <> True
line = file1.ReadLine
params = Split (line)
crt.Session.Connect ("/TELNET " & params(0))
crt.screen.WaitForString "name:",10
crt.Screen.Send "admin" & chr(13)
crt.Screen.WaitForString "Password:"
crt.Screen.Send "admin" & chr(13)
crt.Screen.Send "sy" & chr(13)
crt.Screen.Send "int ran" & chr(9) & "g" & chr(9) & "0/0/1 to" & chr(9) & "g" & chr(9) & "0/0/24 " & chr(13)
crt.Screen.Send "po" & chr(9) & " " & chr(8) & "-i" & chr(9) & "?en" & chr(9) & chr(13)
crt.Screen.Send "qu" & chr(13)
crt.Screen.Send "qu" & chr(13)
crt.Screen.Send "sa" & chr(13)
crt.Screen.WaitForString "Are you sure to continue?[Y/N]"
crt.Screen.Send "y" & chr(13)
crt.Screen.Send "y" & chr(13)
crt.Screen.Send "y" & chr(13)
crt.Session.Disconnect
loop
crt.Screen.Synchronous = False
End Sub
其中IP.TXT是交换机地址,目录一定要按自己电脑上的,我的是存在了桌面,从crt.screen.WaitForString "name:",10 这里开始是你需要更改的脚本部分,也就是你自己录制的部分, crt.Screen.Send "y" & chr(13)这结束,下面是循环部分。good luck。