文章摘要
本文介绍了在Windows系统中使用VBScript语言进行网络Ping测试的代码。代码通过获取对象winmgmts来获取网络信息,并通过execQuery方法获取指定URL的PingStatus数据。然后,代码遍历结果,显示每个Ping测试的结果,包括响应地址、响应名称、字节数和响应时间。该代码的主要目的是测试指定URL的网络可达性,可用于网页服务器的连接测试。
‘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
‘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
© 版权声明
文章版权归作者所有,未经允许请勿转载。



