批量修改交换机

最近由于需要定期保存几百台交换机的配置,同时又要修改一些交换机时间。一直在考虑有个批量工具可以简化工作。经过几天努力,终于如愿一场。
首先做了一个批处理文件,iplist.bat,让它具备了采交换机IP和调用VBS脚本的功能,代码如下:
for /l %%a in (1,1,254) do ping 192.168.20.%%a -n 1 -l 16 -w 100 | find "eply" &echo 192.168.20.%%a >>iplist.txt & echo off        (注:这个不成功,返回的1-254的IP,需修改)
rem 启动telnet
start telnet.exe
rem batch telnet
cscript //nologo tftp.vbs
然后编辑了修改交换机时间的脚本,代码如下:
'This Script is For copy config file to tftp server
'This script is named "tftp.vbs"
On Error Resume Next
dim fSwitchList,objTextStream,objFSO,objSwitch
fSwitchList = "Iplist.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(fSwitchList) Then
 Set objTextStream = objFSO.OpenTextFile(fSwitchList, 1)
Else
 Wscript.Echo "Input file " & fSwitchList & " not found."
 Wscript.Quit
End If
Do Until objTextStream.AtEndOfStream
 objSwitch = objTextStream.ReadLine
 set sh=WScript.CreateObject("WScript.Shell")
 WScript.Sleep 1000
 shtelnet = sh.object
 sh.SendKeys "  open " & objSwitch
 WScript.Sleep 1000
 sh.SendKeys "{ENTER}"
 WScript.Sleep 1000
 sh.SendKeys "enable pass{ENTER}"
 WScript.Sleep 1000
 sh.SendKeys "en{ENTER}"
 WScript.Sleep 1000
 sh.SendKeys "secret  pass{ENTER}"
 WScript.Sleep 1000
 sh.SendKeys "conf t{ENTER}"
 WScript.Sleep 1000
 sh.SendKeys "ntp server 10.128.16.254{ENTER}"
 sh.SendKeys "ntp source vlan 2{ENTER}"
  sh.SendKeys "clock timezone CCT 8{ENTER}"
 sh.SendKeys "end{ENTER}"
 sh.SendKeys "wr{ENTER}"
 WScript.Sleep 5000
 sh.SendKeys " exit{ENTER}"
 sh.SendKeys "{ENTER}"
   Loop
sh.SendKeys " quit{ENTER}"
 objTextStream.Close
 Wscript.quit
 

你可能感兴趣的:(职场,休闲,修改交换机)