如何找到Android设备的LAN IP地址? [英] How to find LAN ip address of android device?
本文介绍了如何找到Android设备的LAN IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果设备的无线连接,我假设该设备由路由器上运行的DHCP具有局域网IP地址分配presumably。
If wifi of device is connected, I assume the device has an LAN IP address assigned presumably by a dhcp running on a router.
如何才能找到它有什么WiFi接口的LAN IP地址(而不是外部IP)?
How can find it what's the LAN ip address (not the external ip) on the wifi interface ?
谢谢,
推荐答案
的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设备的LAN IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文