作者:YANGYANG. | 来源:互联网 | 2023-10-16 15:58
函数代码如下,通讯成功返回True,通讯失败返回False:FunctionPingIP(IP)DimobjWMIService定义SWbemServices对象DimcolIte
函数代码如下,通讯成功返回True,通讯失败返回False:
Function PingIP(IP)
Dim objWMIService '定义SWbemServices对象
Dim colItems 'SWbem对象集合
Dim objItem 'Swbem单个对象
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PingStatus Where Address='"& IP &"'")
For Each objItem In colItems
If objItem.StatusCode = 0 Then
PingIP = True
Else
PingIP = False
End If
Next
end Function
使用方式:
msgbox PingIP("172.16.15.23")