我试图在android中显示连接网络的ip地址。我正在使用以下代码。但它返回2个IPv6 ip地址。如何从中找到正确的ip地址?
我使用以下代码:
List<LinkAddress> linkAddresses = connectivityManager.getLinkProperties(connectivityManager.getActiveNetwork()).getLinkAddresses();
for (LinkAddress linkAddress : linkAddresses) {
Log.i("","LinkAddress getAddress "+linkAddress.getAddress() + "");
Log.i("","Is IPV6 " + (linkAddress.getAddress() instanceof Inet6Address) +"");
Log.i("","Is IPV4 " + (linkAddress.getAddress() instanceof Inet4Address) +"");
Log.i("","Is isLinkLocalAddress " + (linkAddress.getAddress().isLinkLocalAddress()) +"");
Log.i("","Is not isLoopbackAddress " + (!linkAddress.getAddress().isLoopbackAddress()) +"");
}
现在我得到4个ip地址。
LinkAddress getAddress /fe80::2d0:caff:fe00:5ad6
LinkAddress getAddress /2401:4900:2305:14e:2d0:caff:fe00:5ad6
LinkAddress getAddress /2401:4900:2305:14e:28e2:5192:e38f:3e9
LinkAddress getAddress /192.168.43.176
我可以确定fe80是链路本地Ip地址和192。是IPv4地址。但我很困惑,无法从中识别IPV6地址。请帮助我找出IPv6 ip地址。