Android 獲取gateway閘道器地址
阿新 • • 發佈:2018-12-06
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()