JLChen
2020-01-18 cd44a180c4d4a3af3120576e491bde147cfaaf9d
hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/NetUtil/NetWorkUtil.java
@@ -7,6 +7,7 @@
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import com.hdl.sdk.hdl_core.HDLDeviceManger.Core.HDLDeviceManager;
import com.hdl.sdk.hdl_core.Util.LogUtil.HDLLog;
import java.net.InetAddress;
@@ -21,6 +22,17 @@
 */
public class NetWorkUtil {
    private static boolean isGetWifiBroadCast = false;
    public static boolean isIsGetWifiBroadCast() {
        return isGetWifiBroadCast;
    }
    public static void setIsGetWifiBroadCast(boolean isGetWifiBroadCast) {
        NetWorkUtil.isGetWifiBroadCast = isGetWifiBroadCast;
    }
    public static final int GET_LOCAL_IP = 1;
    public static final int GET_MAC_ADDRESS = 2;
    public static final int GET_NETMASK = 3;
@@ -119,6 +131,26 @@
    }
    public static String getLocalBroadCast() {
        String broadCastIp =  "255.255.255.255";
        try {
            //2020-1-17 新或者IP地址方法
            if (isGetWifiBroadCast) {
                broadCastIp = getWifiBroadAddress();
            } else {
                broadCastIp = getLocalBroadCastOld();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (broadCastIp == null) {
            HDLLog.E("getLocalBroadCast error ip null");
        }
        return broadCastIp;
    }
    public static String getLocalBroadCastOld() {
        String broadCastIp = null;
        try {
            Enumeration<?> netInterfaces = (Enumeration<?>) NetworkInterface.getNetworkInterfaces();
@@ -145,7 +177,19 @@
        return broadCastIp;
    }
    public static String getWifiBroadAddress() {
        String ipaddress = "255.255.255.255";
        try {
            WifiManager wifimanage = (WifiManager) HDLDeviceManager.getViewContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);// 获取WifiManager
            DhcpInfo dhcpInfo = wifimanage.getDhcpInfo();
            ipaddress = intToIp((dhcpInfo.ipAddress) | (~dhcpInfo.netmask));
        } catch (Exception ex) {
            ipaddress = "255.255.255.255";
        }
        return ipaddress;
    }
    public static InetAddress getLocalHostLANAddress() throws Exception {