對(duì)于vbs中ping的實(shí)現(xiàn)可以通過兩種方式 :
- 1、調(diào)用系統(tǒng)ping命令;
- 2、使用wmi查詢pingstate類處理。
1、調(diào)用系統(tǒng)ping命令
1
2
|
Set wshell = CreateObject( "WScript.Shell" ) wshell.run( "ping 182.183.101.1" ,0.true) |
對(duì)于以上調(diào)用,如果想對(duì)其進(jìn)行過濾,可以考慮將運(yùn)行結(jié)果重定向到文件,在讀到一個(gè)string中,查找其中是否有timeout或超時(shí)字符,判斷是否超時(shí)。本打算直接拼接命令重定向到文件,但怎么都不成功,所以run調(diào)用一個(gè)bat,bat中寫:ping 192.168.101.1 -n 1 -w 1200
2、使用wmi查詢pingstate類處理:
1
2
3
4
5
6
7
8
9
10
11
12
|
'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 |
到此這篇關(guān)于vbs ping的實(shí)現(xiàn)示例的文章就介紹到這了,更多相關(guān)vbs ping內(nèi)容請(qǐng)搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!
原文鏈接:https://blog.csdn.net/kasteluo/article/details/43155371