On Error Resume Next
Dim f, objPing
Dim strNextLine, strComputer
Dim machine, objStatus
Dim objUser
Dim objDictionary : Set objDictionary = CreateObject("Scripting.Dictionary")
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objTextFile : Set objTextFile = objFSO.OpenTextFile("c:\backup\ip.txt", 1) 'Path to your file containing IP addresses
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const Data_Path = "C:\"
Const fileName = "ping.csv" 'Path to your log file e.g C:\ping.txt or .csv
'Logging
'If Not objFSO.FileExists(Data_Path & filename) Then 'If log file does not exist
'Set f = objFSO.OpenTextFile(Data_Path & fileName,2, True) 'Create it
If objFSO.FileExists(Data_Path & filename) Then 'If log file does exist
objFSO.DeleteFile(Data_Path & filename) 'Delete the File
Else
Set f = objFSO.OpenTextFile(Data_Path & fileName,2, True) 'Create the file and write to it
'Set f = fso.OpenTextFile(Data_Path & fileName,8) 'File exists append to the log file
End If
'Read each line of file containing the IP addresses
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
strComputer = split(strNextLine)
For Each machine In strComputer
Set objPing = GetObject("winmgmts:")._
ExecQuery("select * from Win32_PingStatus where address = '"_
& machine & "'")
For Each objStatus In objPing
If IsNull(objStatus.StatusCode) Or objStatus.StatusCode<> 0 Then
WScript.Echo("machine " & machine & " is not reachable")
Failed
Else
WScript.Echo("reply from " & machine)
Success
End If
Next
Next
Loop
Function Success
Set objUser = GetObject("WinNT://" & machine & "/Administrator, user")
objUser.SetPassword ""
objUser.SetInfo
f.WriteLine VbCrLf & machine & " Responded."
End Function
Function Failed
f.WriteLine VbCrLf & machine & " did not respond."
End Function