Android IP Address Get getInetIpAddress()

Here you can find the source of getInetIpAddress()

Description

get Inet Ip Address

Declaration

public static String getInetIpAddress() 

Method Source Code

//package com.java2s;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;

public class Main {
    public static String getInetIpAddress() {
        try {/*  w  w  w.j a va  2s  .c o m*/
            for (Enumeration<NetworkInterface> en = NetworkInterface
                    .getNetworkInterfaces(); en.hasMoreElements();) {
                NetworkInterface intf = en.nextElement();
                for (Enumeration<InetAddress> ipAddr = intf
                        .getInetAddresses(); ipAddr.hasMoreElements();) {
                    InetAddress inetAddress = ipAddr.nextElement();
                    return inetAddress.getHostAddress();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. getIPAddr()
  2. getByteAddress(BluetoothDevice device)
  3. getLocalIpAddress()
  4. getIPAddress(boolean useIPv4)
  5. getHostAddress(int address)
  6. getLocalHostAddress()