清风细雨楼 Design By www.eepep.com

对于vbs中ping的实现可以通过两种方式 :

  • 1、调用系统ping命令;
  • 2、使用wmi查询pingstate类处理。

1、调用系统ping命令

Set wshell = 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 

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

清风细雨楼 Design By www.eepep.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
清风细雨楼 Design By www.eepep.com