'Create a file to write the result
'============================================================
FileName = "PingResult.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(FileName)) Then
Set resultFile = fso.OpenTextFile(FileName, 8)
else
Set resultFile = fso.CreateTextFile(FileName, true)
end if
subnetID = "192.168.35."
For range = 2 to 254 ' specify range of ip
ipAddress = subnetID & range
if Ping(ipAddress) then
resultFile.writeline ipAddress & " is alive"
else
resultFile.writeline ipAddress & " is dead"
end if
next
'Using Win32_PingStatus class
'============================================================
Function Ping(ipAddress)
Set objWMIService = _
GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_PingStatus " & _
"Where Address = '" & ipAddress & "'")
For Each objItem in colItems
If objItem.StatusCode = 0 Then
Ping = True
else
Ping = False
End If
Next
End Function
Showing posts with label ping. Show all posts
Showing posts with label ping. Show all posts
Wednesday, September 16, 2009
Revised script for IP range ping
Last year i actually wrote a script to do the same thing but the script is not really good and always have the annoyed dos windows pop-up. This time, i using the example on the "Hey, Scripting Guy!" and it is a much much better script in terms of neatness and speed) for doing the same thing
Tuesday, September 9, 2008
Script to ping a range of IP address
I wrote this script last week as i need to find out the IP address for particular storage box. Is not really neat but it did help me in identify the IP address without me brute force myself. To use it, you need to copy and paste the following lines into a text file and save it as "something.vbs". After that just click on it abd the result will be saved in the ping_result.txt file.
'Create a file to write the result
Dim objFile, strGuyFile, strFilePath
strFilePath = "ping_result.txt"
Set objFile = CreateObject("Scripting.
Set strGuyFile = objFile.CreateTextFile(
' Create shell object to run ping
Dim objShell, subnetID, range, result
subnetID = "192.168.37."
Set objShell = WScript.CreateObject("WScript.
For range = 2 to 254 ' the range of ip we want to test
Set objScriptExec = objShell.Exec("ping " & subnetID & range & " -n 1")
result = objScriptExec.StdOut.ReadAll
WScript.Sleep 500
strGuyFile.Write(result)
Next
strGuyFile.Close
Subscribe to:
Posts (Atom)