gpt4 book ai didi

java - Android:如何从 Android 应用程序获取 IP 地址?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:16:16 25 4
gpt4 key购买 nike

是否可以从android应用获取ip地址?

最佳答案

我把它放在我的书签里有一段时间了,但从来没有测试过它:

http://www.droidnova.com/get-the-ip-address-of-your-device,304.html

public String getLocalIpAddress() {
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()) {
return inetAddress.getHostAddress().toString();
}
}
}
} catch (SocketException ex) {
Log.e(LOG_TAG, ex.toString());
}
return null;
}

关于java - Android:如何从 Android 应用程序获取 IP 地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4157880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com