Android 获取gateway网关地址

版权声明:转载请@我原创地址 https://blog.csdn.net/weixin_39706415/article/details/84579872
   my_wifiManager = ((WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE));
            assert my_wifiManager != null;
            dhcpInfo = my_wifiManager.getDhcpInfo();

解析方法 


    public static InetAddress intToInetAddress(int hostAddress) {
        byte[] addressBytes = {(byte) (0xff & hostAddress),
                (byte) (0xff & (hostAddress >> 8)),
                (byte) (0xff & (hostAddress >> 16)),
                (byte) (0xff & (hostAddress >> 24))};

        try {
            return InetAddress.getByAddress(addressBytes);
        } catch (UnknownHostException e) {
            throw new AssertionError();
        }
    }

获取方式 

intToInetAddress(dhcpInfo.gateway).getHostAddress()

猜你喜欢

转载自blog.csdn.net/weixin_39706415/article/details/84579872