以下为配置文件格式:
//ipstart-ipend区域为IP地址范围
ipstart
192.168.25.\7-8\18-23
ipend
//configurestart-configureend区域内容为需要执行的命令
configurestart
admin
88888888
enable
admin
sys reboot
y
configureend
以下为主要代码:
Set gnwfso = CreateObject("Scripting.FileSystemObject")
Set gnwsh = WScript.CreateObject("WScript.Shell")
filepath = gnwfso.GetFolder(".").Path & "\" &"info.txt"
Set gnwfile = gnwfso.GetFile(filepath)
Set gnwfilestream = gnwfile.OpenAsTextStream()
Set gnwip = CreateObject("Scripting.Dictionary")
Set gnwconfig = CreateObject("Scripting.Dictionary")
Dim gnwkey
gnwkdy = 1
Do While gnwfilestream.AtEndOfStream = False
gnwlines = Trim(gnwfilestream.ReadLine)
If InStr(gnwlines,"ipstart") = 1 Then
Do While 1
gnwline = Trim(gnwfilestream.ReadLine)
If InStr(gnwline,"ipend")=1 Then
Exit Do
End If
ips = Trim(Left(gnwline,InStr(gnwline,"\")-1))
ipex = Trim(Mid(gnwline,InStr(gnwline,"\")+1))
Do While 1
If InStr(ipex,"\") = 0 Then
If InStr(ipex,"-") <> 0 Then
For counter = CInt(Trim(Left(ipex,InStr(ipex,"-")-1))) To CInt(Trim(Mid(ipex,InStr(ipex,"-")+1)))
gnwip.Add CStr(gnwkdy), ips & CStr(counter)
gnwkdy = gnwkdy + 1
Next
Else
gnwip.Add CStr(gnwkdy), ips & Trim(ipex)
gnwkdy = gnwkdy + 1
End If
Exit Do
Else
iptem = Trim(Left(ipex,InStr(ipex,"\")-1))
If InStr(iptem ,"-") <> 0 Then
For counter = CInt(Trim(Left(iptem,InStr(iptem,"-")-1))) To CInt(Trim(Mid(iptem,InStr(iptem,"-")+1)))
gnwip.Add CStr(gnwkdy), ips & CStr(counter)
gnwkdy = gnwkdy + 1
Next
Else
gnwip.Add CStr(gnwkdy), ips & Trim(iptem)
gnwkdy = gnwkdy + 1
End If
ipex = Trim(Mid(ipex,InStr(ipex,"\")+1))
End If
Loop
Loop
End If
If InStr(gnwlines,"configurestart") = 1 Then
Do While 1
gnwline = Trim(gnwfilestream.ReadLine)
If InStr(gnwline,"configureend")=1 Then
Call gnwshow
Call gnwtelnetconfig
gnwip.RemoveAll
gnwconfig.RemoveAll
gnwkdy=1
Exit Do
End If
gnwconfig.Add CStr(gnwkdy),gnwline
gnwkdy = gnwkdy + 1
Loop
End If
Loop
gnwfilestream.Close
Function gnwshow
ipshow = ""
For Each key In gnwip.Keys
ipshow =ipshow & gnwip(key) & " "
Next
End Function
Function gnwtelnetconfig ()
For Each ipkey In gnwip.Keys
' WScript.Sleep 31000
' gnwsh.SendKeys "{ENTER}"
' WScript.Sleep 1000
' gnwsh.SendKeys "{ENTER}"
' gnwsh.SendKeys "open " & gnwip(ipkey) & "{ENTER}"
set sh=WScript.CreateObject("WScript.Shell")
sh.run "telnet " & gnwip(ipkey)
WScript.Sleep 1000
For Each key In gnwconfig.keys
WScript.Sleep 1000
gnwsh.SendKeys gnwconfig(key) & "{ENTER}"
Next
WScript.Sleep 2000
gnwsh.SendKeys "^]"
WScript.Sleep 1000
gnwsh.SendKeys "quit{ENTER}"
WScript.Sleep 1000
Next End Function
'gnwsh.SendKeys "quit{ENTER}"
MsgBox "命令执行完毕 "
WScript.Quit
1