写一段能在idea 上运行的 通过ONVIF 发现资产类型、名称、品牌、型号、版本等信息的设备列表信息的代码,并加上中文注释
时间: 2023-12-26 12:05:33 浏览: 36
以下是一段能在Idea上运行的通过ONVIF发现资产类型、名称、品牌、型号、版本等信息的设备列表信息的代码,已加上中文注释。
```java
import java.net.URL;
import java.util.List;
import org.onvif.ver10.device.wsdl.Device;
import org.onvif.ver10.device.wsdl.GetDeviceInformationResponse;
import org.onvif.ver10.device.wsdl.GetScopesResponse;
import org.onvif.ver10.device.wsdl.GetServicesResponse;
import org.onvif.ver10.discovery.wsdl.Discovery;
import org.onvif.ver10.discovery.wsdl.DiscoveryPortType;
import org.onvif.ver10.schema.Capabilities;
import org.onvif.ver10.schema.DeviceInformation;
import org.onvif.ver10.schema.Service;
public class OnvifDiscovery {
public static void main(String[] args) {
try {
// 构建ONVIF设备发现服务的URL对象
URL deviceDiscoverUrl = new URL("soap.udp://239.255.255.250:3702");
// 构建ONVIF设备发现服务的客户端对象
Discovery discovery = new Discovery(deviceDiscoverUrl);
// 获取ONVIF设备发现服务的端口对象
DiscoveryPortType discoveryPort = discovery.getDiscoveryPort();
// 发送设备发现请求,获取设备列表信息
List<Device> devices = discoveryPort.probe(null, null, null);
// 遍历设备列表信息,输出设备的资产类型、名称、品牌、型号、版本等信息
for (Device device : devices) {
System.out.println("发现设备:" + device.getScopes().getScope().get(0).getValue());
System.out.println("设备资产类型:" + device.getDeviceInformation().getDeviceType());
System.out.println("设备名称:" + device.getDeviceInformation().getFriendlyName());
System.out.println("设备品牌:" + device.getDeviceInformation().getManufacturer());
System.out.println("设备型号:" + device.getDeviceInformation().getModel());
System.out.println("设备版本:" + device.getDeviceInformation().getFirmwareVersion());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
```
注意:该代码需要依赖于org.onvif.jar库,需要将其添加到项目中。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)