Open aww-aww opened 12 years ago
I am working on this issue before releasing 2.1. The current approach is to acquire Wifi ip first (WifiInfo could only return ipv4 in integer). Then use java.net.NetworkInterface to find all possible ip addresses and return the first available one. Actually the network interface provides both ipv4 and ipv6 right now, but since ipv6 comes first and got returned immediately, then the value is always in ipv6, i.e. "fe80::eacc:607b:8068:acb2%rmnet0". We could use NetworkInterface alone to get both ipv4 and ipv6 at same time, and upload them in a list.
Another approach will be building a socket (maybe connect to www.google.com with port 80) and fetch the local ip address directly from socket.getLocalAddress().getHostAddress(). Then the ipv6 is handled internally. But all those approaches didn't consider NAT in the cellular network. If we are interested in the real cellular ip over internet, we might consider to use ping with ttl 1 or 2 to find that ip address.
The current approach assumes a 32 bit int. It would require a bit of reordering, but the easiest fix is probably checking the size of InetAddress.getByAddress(bytes) initially and handling it as v4 if it is 4 bytes and v6 if it is 16 bytes.