Sometimes you may come across the need of checking a number of machines are connected to network or not. There is an easy way to do it through vbscript.
To accomplish this you need two files. Create a text file named “MachineList.txt” and list all the machine names or ip addresses in the list as shown below
192.168.1.2
192.168.1.3
192.168.1.4
192.168.1.5
192.168.1.6
Test1
test2
Then copy the below vbscript in a notepad file and save it as “pinglist.vbs”. Double click on the “pinglist.vbs”. You will get the results in another text file named “updated.txt” on the same folder.
On Error Resume Next
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set Fso = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("WScript.Shell")
Set InputFile = fso.OpenTextFile("MachineList.Txt")
Set outputFile = fso.openTextFile("updated.Txt", ForAppending, True)
outputFile.writeline "Date : " & Date
Do While Not (InputFile.atEndOfStream)
HostName = InputFile.ReadLine
Set WshShell = WScript.CreateObject("WScript.Shell")
Ping = WshShell.Run("ping -n 1 " & HostName, 0, True)
Select Case Ping
Case 0
outputFile.writeline HostName & " Connected"
Case 1
outputFile.writeline HostName & " Not Connected"
End Select
Loop