Java IP Address Get getHostIp()

Here you can find the source of getHostIp()

Description

get Host Ip

License

Apache License

Declaration

public static String getHostIp() 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Main {
    private static InetAddress netAddress = null;

    public static String getHostIp() {
        if (null == getInetAddress()) {
            return null;
        }/*from   w ww . j  a v a2 s  .  c  o m*/
        String ip = getInetAddress().getHostAddress(); //get the ip address
        return ip;
    }

    public static InetAddress getInetAddress() {
        if (netAddress == null) {
            try {
                netAddress = InetAddress.getLocalHost();
            } catch (UnknownHostException e) {
                System.out.println("unknown host!");
            }
        }
        return netAddress;
    }
}

Related

  1. getExternalIPAddress()
  2. getExternalIPAddress()
  3. getFirstLocalNonLoopbackIpAddress()
  4. getFirstNonLoopbackAddress(boolean preferIpv4, boolean preferIPv6)
  5. getFirstNonLoopBackAddress(boolean preferIpv4, boolean preferIPv6)
  6. getHostIp()
  7. getHostIP()
  8. getHostIP()
  9. getHostIP()