From 93f031deaf3e17b6de44dfd56d4515a1cfcb6044 Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期日, 12 十二月 2021 22:32:47 +0800 Subject: [PATCH] 默认发数据主网关 --- HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/IpUtils.java | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 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..2f2f010 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 @@ -37,6 +37,23 @@ return "255.255.255.255"; } + public static boolean isLocalIpAddress(String ipAddress) { + try { + for (Enumeration<NetworkInterface> niEnum = NetworkInterface.getNetworkInterfaces(); + niEnum.hasMoreElements(); ) { + NetworkInterface ni = niEnum.nextElement(); + for (InterfaceAddress interfaceAddress : ni.getInterfaceAddresses()) { + if (ipAddress.equals(interfaceAddress.getAddress().getHostAddress())) { + return true; + } + } + } + } catch (SocketException e) { + e.printStackTrace(); + } + return false; + } + public static String getIP(Context application) { WifiManager wifiManager = (WifiManager) application.getApplicationContext().getSystemService(Context.WIFI_SERVICE); if (!wifiManager.isWifiEnabled()) { -- Gitblit v1.8.0