由于工作需要,处理上百个机器也是常见的事情。这里我们主要介绍一下创建一个telnet批处理程序来帮助完成工作,那么这里我们为大家呈现了具体的代码。希望对大家有所帮助。首先做了一个批处理文件,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
这一步telnet批处理的设置,编辑了修改交换机时间的脚本,代码如下:
- '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
- shshtelnet = 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
到这里我们就完成了telnet批处理的脚本设置了。