如何找到Android设备的局域网IP地址?
2019年05月18日
作者:佚名
如果连接了设备的wifi,我假设设备有一个LAN IP地址,可能是由路由器上运行的dhcp分配的.
怎么能找到wifi接口上的LAN IP地址(不是外部ip)?
谢谢,
解决方法
NetworkInterface将帮助您:
String ipAddress = null; try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { ipAddress = inetAddress.getHostAddress().toString(); } } } } catch (SocketException ex) {}
以上是来客网为你收集整理的如何找到Android设备的局域网IP地址?全部内容,希望文章能够帮你解决如何找到Android设备的局域网IP地址?所遇到的程序开发问题。
如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。