Dirección IP de la tableta Android

Here I am facing an issue regarding obtaining Android Tablet IP address.

I am using the following code for the tablet IP addess in a generic way.

  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();

inetAddress.getHostAddress() method returns IP address as fe80::9a4b:4aff:fe00:a6e1 ,which is a different format rather than 122.xx.xxx.xxx formato.

When I use Wifimanager class to obtain tablet IP address it returns 122.xx.xxx.xxx in this format only.

But using the generic way I don't know why it is giving as wrong format.

Can any one please help me on this issue...

Gracias de antemano.

preguntado el 08 de noviembre de 11 a las 09:11

I don't know much about android APIs, but AFAIK, fe80::9a4b:4aff:fe00:a6e1 is too big to be an IP address. Looks like you're using the wrong method. -

3 Respuestas

fe80::9a4b:4aff:fe00:a6e1 is not wrong at all. It is just new-style, IPv6.

New appliactions always should be designed to be able to work in both formats.

respondido 08 nov., 11:13

That is an IPv6 address. Have a look at artículo de Wikipedia for a start. It may be possible to convert an IPv6 address to an IPv4 address (i.e. xxx.xxx.xxx.xxx) but it's not guaranteed.

respondido 08 nov., 11:13

Thnaks for the reply. We try to convert the IP6 to IP4 ,whatever converted IP is not matched with the IP address is not matched with the WifiManager class returning value. - PoornaDroid

/* look through the available network interfaces and pick the first "decent" IPv4 address. * As the emulator uses by default, only use it if nothing better is available. */

public String getMyIp() {
        Set<String> eligible = eligibleIpAddresses();

/* For the emulator, prefer an IP address other than (default emulator address)
             * but use it if it is the only one. */
        if (eligible.size() > 1) {
            return eligible.iterator().next();
        } else if (eligible.size() == 1) {
            return eligible.iterator().next();
        } else {
            Log.w("Using local IP address, no external objects will be discovered","---");
            return "";

    public static Set<String> eligibleIpAddresses() {
        Set<String> eligible = new HashSet<String>();
        try {
            Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
            while (netInterfaces.hasMoreElements()) {
                NetworkInterface ni = netInterfaces.nextElement();
                Enumeration<InetAddress> address = ni.getInetAddresses();
                while (address.hasMoreElements()) {
                    InetAddress addr = address.nextElement();
                    if (!addr.isLoopbackAddress() && !(addr.getHostAddress().indexOf(":") > -1)) {
        } catch (Exception e) {
        return eligible;

respondido 08 nov., 11:14

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.