Java Utililty Methods IP Address Get

List of utility methods to do IP Address Get

Description

The list of methods to do IP Address Get are organized into topic(s).

Method

StringgetLocalIP()
get Local IP
String sIP = "";
InetAddress ip = null;
try {
    boolean bFindIP = false;
    Enumeration<NetworkInterface> netInterfaces = (Enumeration<NetworkInterface>) NetworkInterface
            .getNetworkInterfaces();
    while (netInterfaces.hasMoreElements()) {
        if (bFindIP) {
...
InetAddressgetLocalIP()
Retrieves the IP address of the local computer: - If there exists an interface different from "loopback" it will never return "127.0.0.1" - If there exists multiple network interfaces, the first one will be returned
try {
    Collection<InterfaceAddress> ips = getAllIPAddresses();
    if (ips.size() > 0) {
        return (InetAddress) ips.iterator().next().getAddress();
    } else {
        return null;
} catch (Exception e) {
...
StringgetLocalIp()
get Local Ip
try {
    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
    while (interfaces.hasMoreElements()) {
        NetworkInterface current = interfaces.nextElement();
        if (!current.isUp() || current.isLoopback() || current.isVirtual()) {
            continue;
        Enumeration<InetAddress> addresses = current.getInetAddresses();
...
StringgetLocalIP()
get Local IP
StringBuilder IFCONFIG = new StringBuilder();
try {
    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() && !inetAddress.isLinkLocalAddress()
...
StringgetLocalIP()
get Local IP
try {
    return InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
    e.printStackTrace();
return null;
StringgetLocalIP()
Looks up the IP number of the local host.
String result;
try {
    result = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
    result = "UNKNOWNIP";
return result;
StringgetLocalIp()
get Local Ip
try {
    Enumeration<NetworkInterface> ifs = NetworkInterface.getNetworkInterfaces();
    while (ifs.hasMoreElements()) {
        NetworkInterface iface = ifs.nextElement();
        if (iface.isUp()) {
            Enumeration<InetAddress> adds = iface.getInetAddresses();
            while (adds.hasMoreElements()) {
                InetAddress addr = adds.nextElement();
...
StringgetLocalIp()
get Local Ip
String localIp = "";
try {
    localIp = InetAddress.getLocalHost().getHostAddress();
    if ("/".equals(System.getProperties().getProperty("file.separator"))) {
        Enumeration<?> netInterfaces = NetworkInterface.getNetworkInterfaces();
        InetAddress ip = null;
        while (netInterfaces.hasMoreElements()) {
            NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement();
...
StringgetLocalIP()
get Local IP
if (cacheIP == null) {
    synchronized (cacheLock) {
        if (cacheIP == null) {
            try {
                cacheIP = getLocalIPByNetworkInterface();
            } catch (Exception e) {
            if (cacheIP == null) {
...
StringgetLocalIp()
get Local Ip
try {
    for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) {
        NetworkInterface item = e.nextElement();
        for (InterfaceAddress address : item.getInterfaceAddresses()) {
            if (address.getAddress() instanceof Inet4Address) {
                Inet4Address inet4Address = (Inet4Address) address.getAddress();
                if (inet4Address.isLoopbackAddress()) {
                    continue;
...