public static List<InetAddress> hostAddresses(){
  List<InetAddress> addrList=new ArrayList<>();
  Enumeration<NetworkInterface> IFCs=null;
  try {
    IFCs=NetworkInterface.getNetworkInterfaces();
  }
 catch (  SocketException ex) {
    log.error("Unable to get network interfaces.",ex);
  }
  if (IFCs != null) {
    while (IFCs.hasMoreElements()) {
      NetworkInterface IFC=IFCs.nextElement();
      try {
        if (IFC.isUp()) {
          Enumeration<InetAddress> addresses=IFC.getInetAddresses();
          while (addresses.hasMoreElements()) {
            InetAddress address=addresses.nextElement();
            if (!address.isLoopbackAddress() && !address.isLinkLocalAddress()) {
              addrList.add(address);
            }
          }
        }
      }
 catch (      SocketException ex) {
        log.error("Unable to read network interface {}.",IFC.toString(),ex);
      }
    }
  }
  return addrList;
}

public static List < InetAddress > hostAddresses ( ) { List < InetAddress > addrList = new ArrayList < > ( ) ; Enumeration < NetworkInterface > IFCs = null ; try { IFCs = NetworkInterface . getNetworkInterfaces ( ) ; } catch ( SocketException ex ) { log . error ( "Unable to get network interfaces." , ex ) ; } if ( IFCs != null ) { while ( IFCs . hasMoreElements ( ) ) { NetworkInterface IFC = IFCs . nextElement ( ) ; try { if ( IFC . isUp ( ) ) { Enumeration < InetAddress > addresses = IFC . getInetAddresses ( ) ; while ( addresses . hasMoreElements ( ) ) { InetAddress address = addresses . nextElement ( ) ; if ( ! address . isLoopbackAddress ( ) && ! address . isLinkLocalAddress ( ) ) { addrList . add ( address ) ; } } } } catch ( SocketException ex ) { log . error ( "Unable to read network interface {}." , IFC . toString ( ) , ex ) ; } } } return addrList ; }
a list of the non - loopback , non - link - local ip addresses of the host , or null if none found .
