From 0188dee359636723190f0f67a6b674b7b08f7bef Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期一, 21 三月 2022 09:55:01 +0800 Subject: [PATCH] 增加判断json数据格式 --- HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/IpUtils.java | 29 +++++++++++++++++++++++------ 1 files changed, 23 insertions(+), 6 deletions(-) diff --git a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/IpUtils.java b/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/IpUtils.java index f35cfb9..97620f2 100644 --- a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/IpUtils.java +++ b/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/IpUtils.java @@ -19,22 +19,39 @@ * @return 骞挎挱鍦板潃 */ public static String getBroadcastAddress() { +// try { +// for (Enumeration<NetworkInterface> niEnum = NetworkInterface.getNetworkInterfaces(); +// niEnum.hasMoreElements(); ) { +// NetworkInterface ni = niEnum.nextElement(); +// if (!ni.isLoopback()) { +// for (InterfaceAddress interfaceAddress : ni.getInterfaceAddresses()) { +// if (interfaceAddress.getBroadcast() != null) { +// return interfaceAddress.getBroadcast().toString().substring(1); +// } +// } +// } +// } +// } catch (SocketException e) { +// e.printStackTrace(); +// } + return "255.255.255.255"; + } + + public static boolean isLocalIpAddress(String ipAddress) { try { for (Enumeration<NetworkInterface> niEnum = NetworkInterface.getNetworkInterfaces(); niEnum.hasMoreElements(); ) { NetworkInterface ni = niEnum.nextElement(); - if (!ni.isLoopback()) { - for (InterfaceAddress interfaceAddress : ni.getInterfaceAddresses()) { - if (interfaceAddress.getBroadcast() != null) { - return interfaceAddress.getBroadcast().toString().substring(1); - } + for (InterfaceAddress interfaceAddress : ni.getInterfaceAddresses()) { + if (ipAddress.equals(interfaceAddress.getAddress().getHostAddress())) { + return true; } } } } catch (SocketException e) { e.printStackTrace(); } - return "255.255.255.255"; + return false; } public static String getIP(Context application) { -- Gitblit v1.8.0