方法1:调用系统ping命令
代码如下:
Set wshell = CreateObject(“WScript.Shell”)
wshell.run(“ping 182.183.101.1″,0.true)
对于以上调用,如果想对其进行过滤,可以考虑将运行结果重定向到文件,在读到一个string中,查找其中是否有timeout或超时字符,判断是否超时。
方法2:使用wmi查询pingstate类处理
代码如下:
‘url = “www.baidu.com”
url = “119.75.217.109″
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2″)
Set colPings = objWMIService.ExecQuery (“Select * From Win32_PingStatus where Address = ‘” & url & “‘”)
For Each objPing in colPings
MsgBox url & ” responded to ping.” & vbcrlf &_
“Responding Address: ” & objPing.ProtocolAddress & vbcrlf &_
“Responding Name: ” & objPing.ProtocolAddressResolved & vbcrlf &_
“Bytes Sent: ” & objPing.BufferSize & vbcrlf &_
“Time: ” & objPing.ResponseTime & ” ms”
Next