CT Group Pty Ltd logo

VBScript - Pinging multiple IP addresses

A short while ago we needed to find the IP address of a new network device and were having trouble getting it running. The end result was we had to use brute force, and instead of sitting there typing to figure it out, wrote a small script and let it run. This script will only work on Windows XP or greater. The script pings IP within the intStartIP and intEndIP variables specificied and lets you know if an IP address returns results. Copy and paste the code below into a file called ping.vbs and set the first three variables as needed and then double click to run it.

strSubnet = "192.168.0."

intStartIP = 2

intEndIP = 254

strResult = "No response"

 

x = intStartIP

 

Do Until x > intEndIP

   strIP = CStr(x)

      strComputer = strSubnet & strIP

 

   Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

 

   Set colItems = objWMIService.ExecQuery _

       ("Select * from Win32_PingStatus " & _

           "Where Address = '" & strComputer & "'")

 

   For Each objItem in colItems

       If objItem.StatusCode = 0 Then

           WScript.Echo (strComputer & " - Reply received.")

       strResult = "Reply received"

       End If

   Next

   x = x + 1

Loop

 

WScript.Echo ("Ping test ended - " & strResult)

CSET Technologies is a member of
CT Group Pty Ltd, © 2017