對于vbs中ping的實現可以通過兩種方式 :
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 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"Next
到此這篇關于vbs ping的實現示例的文章就介紹到這了,更多相關vbs ping內容請搜索武林網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持武林網!
新聞熱點
疑難解答