Reputation: 36
Hi guys I've gone through a lot of coding on line to get my android mobiles IP address Most of them are ending with
if (!inetAddress.isLoopbackAddress())
{ return inetAddress.getHostAddress().toString(); }
How ever i get something that looks like this:- "fe80::a00:27ff:fe37:28b5%eth1" Weird cause I was expecting something like xxx.xxx.xxx.xxx
Can some one help me understand whats this?
Upvotes: 1
Views: 7080
Reputation: 28823
Its returning IPV6 address.
Check if its IPV4 address before returning result.
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
return inetAddress.getHostAddress().toString();
}
Hope this helps.
Upvotes: 1
Reputation: 13967
That is an IPv6 address. Additionally, since it starts with fe80::
you know it's also a link-local IPv6 address, so cannot be used for communication beyond the local network. (in this case, eth1
, since that is the scope specified at the end after the %
- but note that using a %
to identify the scope isn't always valid when using an IPv6 address.)
Upvotes: 2