Java IP Address Get getLocalIPAddress()

Here you can find the source of getLocalIPAddress()

Description

get Local IP Address

License

Open Source License

Declaration

public static String getLocalIPAddress() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.InetAddress;

import java.net.UnknownHostException;

public class Main {
    public static String getLocalIPAddress() {
        return checkIP(getIPFromAPI());
    }/*from  ww  w  .ja va2 s .  c  o m*/

    private static String checkIP(String IPAddress) {
        if (IPAddress == null || IPAddress.equals("127.0.0.1")) {
            return "<unknown>";
        }

        return IPAddress;
    }

    private static String getIPFromAPI() {
        try {
            InetAddress IP = InetAddress.getLocalHost();
            return IP.getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related

  1. getLocalIP()
  2. getLocalIP()
  3. getLocalIp()
  4. getLocalIp(final boolean useIpv6)
  5. getLocalIPAddress()
  6. getLocalIPAddress()
  7. getLocalIpAddress()
  8. getLocalIpAddress()
  9. getLocalIPAddresses()