Ping multiple server and display IP with status.

This script will ping multiple server available in servers.txt and display IP with status.
Copy below contents and save as filename.vbs and create a servers.txt will all server names one per line.

************************************************************************************************************

Const ForReading = 1
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objShell = CreateObject(“WScript.Shell”)
If not objFSO.FileExists(“servers.txt”) THEN
wscript.echo “Please create a file named ‘servers.txt’ with one PC name to be pinged per line,”&_
vbcrlf&”with a hard return at the end of each line.”
wscript.quit
end if
tempobj=”temp.txt”

Set objTextFile = objFSO.OpenTextFile(“servers.txt”, ForReading)
logfile=”results.csv”
Set ofile=objFSO.CreateTextFile(logfile,True)
strText = objTextFile.ReadAll
objTextFile.Close
wscript.echo “Ping batch starting, please be patient. This could take some time to”&_
vbcrlf&”finish, depending on the number of hosts to check. You “_
&”will be “&vbcrlf&”notified upon the completion of this script.”
ofile.WriteLine “,”&”Ping Report — Date: ” & Now() & vbCrLf
arrComputers = Split(strText, vbCrLF)
for each item in arrcomputers
objShell.Run “cmd /c ping -n 1 -w 1000 ” & item & ” >temp.txt”, 0, True
Set tempfile = objFSO.OpenTextFile(tempobj,ForReading)
Do Until tempfile.AtEndOfStream
temp=tempfile.readall
striploc = InStr(temp,”[“)
If striploc=0 Then
strip=””
Else
strip=Mid(temp,striploc,16)
strip=Replace(strip,”[“,””)
strip=Replace(strip,”]”,””)
strip=Replace(strip,”w”,” “)
strip=Replace(strip,” “,””)
End If

If InStr(temp, “Reply from”) Then
ofile.writeline item & “,”&strip&”,”&”Online.”
ElseIf InStr(temp, “Request timed out.”) Then
ofile.writeline item &”,”&strip&”,”&”No response (Offline).”
ELSEIf InStr(temp, “try again”) Then
ofile.writeline item & “,”&strip&”,”&”Unknown host (no DNS entry).”

End If
Loop
Next
tempfile.close
objfso.deletefile(tempobj)
ofile.writeline
ofile.writeline “,”&”Ping batch complete “&now()
wscript.echo “Ping batch completed. The results will now be displayed.”
objShell.Run(“””C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office\excel.exe “””&logfile)

************************************************************************************************************

Thanks,
WintelAdmin

Facebook Comments
Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *