在多个IP上运行VBScript

时间:2017-09-11 07:03:38

标签: vbscript

我有一个VBS文件,它通过telnet连接到一些旧硬件。 我想在多个IP上运行VBS。

我应该在telnet脚本中更改什么才能从TXT文件中选择IP并在每个IP上运行脚本?

类似下面的ping示例,但没有输出文件。

Telnet VBS文件:

Option Explicit
Dim oShell
Set oShell = WScript.CreateObject("WScript.Shell")
oShell.Run "telnet"
WScript.Sleep 4000
oShell.SendKeys "open 192.168.194.82~"
WScript.Sleep 4000
oShell.SendKeys "admin~"
WScript.Sleep 4000
oShell.SendKeys "This is the password~"
WScript.Sleep 4000
oShell.SendKeys "system~"
WScript.Sleep 4000
oShell.SendKeys "restart~"
oShell.SendKeys "yes~"
WScript.Quit

Ping示例:

Dim strInputPath, strOutputPath, strStatus
Dim objFSO, objTextIn, objTextOut 
strInputPath = "c:\ip-list.txt" '- location of input
strOutputPath = "c:\ip-list-output.csv" '- location of output 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextIn = objFSO.OpenTextFile(strInputPath, 1)
Set objTextOut = objFSO.CreateTextFile(strOutputPath)
objTextOut.WriteLine("computer,status") 
Do Until objTextIn.AtEndOfStream = True
    strComputer = objTextIn.ReadLine
    If fPingTest(strComputer) Then
         strStatus = "UP"
    Else
         strStatus = "DOWN"
    End If
    objTextOut.WriteLine(strComputer & "," & strStatus)
Loop

Function fPingTest(strComputer)
    Dim objShell, objPing
    Dim strPingOut, flag
    Set objShell = CreateObject("WScript.Shell")
    Set objPing = objShell.Exec("ping " & strComputer)
    strPingOut = objPing.StdOut.ReadAll
    If InStr(LCase(strPingOut), "reply") Then
        flag = True
    Else
        flag = False
    End If
    fPingTest = flag 
End Function

0 个答案:

没有答案