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.
FileSystemObject")
Set strGuyFile = objFile.CreateTextFile(
strFilePath, true)

' Create shell object to run ping
Dim objShell, subnetID, range, result
subnetID = "192.168.37."
Set objShell = WScript.CreateObject("WScript.
Shell")

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

No comments: