平时很少用到ping命令,所以这个类也没怎么用过,测试了一下,好像效率比ping要高。计算ping 100次jb51.net延迟的平均值。
代码如下:
IP = "jb51.net"
WQL = "Select * from Win32_PingStatus Where Address = '$IP'"
WQL = Replace(WQL,"$IP",IP)
n = 0 : s = 0
Do Until n = 100
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery(WQL,,48)
For Each objItem in colItems
If objItem.StatusCode = 0 Then
s = s + objItem.ResponseTime
n = n + 1
End If
Next
Loop
WScript.Echo "Average:" & s / n