The following code will ping a semi-colon de-limited list of computers, displaying output on the command windows. Save the file as ping.vbs and call using the following command: cscript.exe ping.vbs
Set WshShell = CreateObject(“WScript.Shell”)
strPCs = “host1;host2”
strPCs = Split(strPCs,”;”)
For each PC in strPCs
PingTest(PC)
Next
Sub PingTest(strComputer)
Set objScriptExec = WshShell.Exec(“ping ” & strComputer)
Do While Not objscriptexec.Stdout.AtEndOfStream
str = objscriptexec.Stdout.ReadLine
If InStr(1,str,”Lost = 0″,1) > 0 Then
WScript.Echo(” ” & strComputer & “: OK – 100%”)
ElseIf InStr(1,str,”Lost = 1″,1) > 0 Then
WScript.Echo(” ” & strComputer & “: FAIL – 75%”)
ElseIf InStr(1,str,”Lost = 2″,1) > 0 Then
WScript.Echo(” ” & strComputer & “: FAIL – 50%”)
ElseIf InStr(1,str,”Lost = 3″,1) > 0 Then
WScript.Echo(” ” & strComputer & “: FAIL – 25%”)
ElseIf InStr(1,str,”Lost = 4″,1) > 0 Then
WScript.Echo(” ” & strComputer & “: FAIL – 0%”)
End If
Loop
End Sub