【发布时间】:2013-12-01 22:14:36
【问题描述】:
我正在尝试找到一种方法来查看任何一台设备上的所有可用 IP 地址?
这是我在 Android 上使用的:
public String[] getLocalIpAddress()
{
ArrayList<String> addresses = new ArrayList<String>();
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()) {
addresses.add(inetAddress.getHostAddress().toString());
}
}
}
} catch (SocketException ex) {
String LOG_TAG = null;
Log.e(LOG_TAG, ex.toString());
}
return addresses.toArray(new String[0]);
}
谢谢
【问题讨论】:
标签: c# windows-phone-8 ip-address