vbs ping實現(xiàn)的兩種方式
對于vbs中ping的實現(xiàn)可以通過兩種方式 :
- 1、調(diào)用系統(tǒng)ping命令;
- 2、使用wmi查詢pingstate類處理。
1、調(diào)用系統(tǒng)ping命令
Set wshell = CreateObject("WScript.Shell") wshell.run("ping 182.183.101.1",0.true)
對于以上調(diào)用,如果想對其進行過濾,可以考慮將運行結(jié)果重定向到文件,在讀到一個string中,查找其中是否有timeout或超時字符,判斷是否超時。本打算直接拼接命令重定向到文件,但怎么都不成功,所以run調(diào)用一個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
到此這篇關于vbs ping的實現(xiàn)示例的文章就介紹到這了,更多相關vbs ping內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
VBS教程:VBScript 語句-Property Let 語句
VBS教程:VBScript 語句-Property Let 語句...2006-11-11MSScriptControl.ScriptControl組件屬性、方法、事件介紹
這篇文章主要介紹了MSScriptControl.ScriptControl組件屬性、方法、事件介紹,需要的朋友可以參考下2014-08-08