◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
2、使用wmi查询pingstate类处理。
12 | Setwshell = CreateObject("WScript.Shell")wshell.run("ping 182.183.101.1",0.true) |
对于以上调用,如果想对其进行过滤,可以考虑将运行结果重定向到文件,在读到一个string中,查找其中是否有timeout或超时字符,判断是否超时。本打算直接拼接命令重定向到文件,但怎么都不成功,所以run调用一个bat,bat中写:ping 192.168.101.1 -n 1 -w 1200
123456789101112 |
'url = "www.baidu.com"url = "119.75.217.109"strComputer = "."SetobjWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"& strComputer & "\root\cimv2")SetcolPings = objWMIService.ExecQuery ("Select * From Win32_PingStatus where Address = '"& url & "'")ForEachobjPing in colPingsMsgBox url & " responded to ping."& vbcrlf &_"Responding Address: "& objPing.ProtocolAddress & vbcrlf &_"Responding Name: "& objPing.ProtocolAddressResolved & vbcrlf &_"Bytes Sent: "& objPing.BufferSize & vbcrlf &_"Time: "& objPing.ResponseTime & " ms" |
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。