Ping
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForAppending = 8
Const ForReading = 1
'定义输出结果
Set objTextFile = objFSO.OpenTextFile ("d:\Ping_Result.txt", ForAppending, True)
'定义服务器IP列表
Set ts = objFSO.OpenTextFile("d:\serverlist.txt", ForReading)
do until ts.AtEndOfStream '判断是否到文件末尾
IP = ts.readline
WQL = "Select * from Win32_PingStatus Where Address = '$IP'"
WQL = Replace(WQL,"$IP",IP)
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery(WQL,,48)
For Each objItem in colItems
If objItem.StatusCode = 0 Then
objTextFile.WriteLine IP & " " & "可以Ping通"
Else
objTextFile.WriteLine IP & " " & "无法Ping通"
End If
Next
loop
ts.close
msgbox "脚本执行完成,输出结果位于 d:\Ping_Result.txt"