public static synchronized Collection<String> allLocalIps(){
  List<String> ips=new ArrayList<>(4);
  try {
    Enumeration<NetworkInterface> itfs=NetworkInterface.getNetworkInterfaces();
    if (itfs != null) {
      for (      NetworkInterface itf : asIterable(itfs)) {
        if (!itf.isLoopback()) {
          Enumeration<InetAddress> addrs=itf.getInetAddresses();
          for (          InetAddress addr : asIterable(addrs)) {
            String hostAddr=addr.getHostAddress();
            if (!addr.isLoopbackAddress() && !ips.contains(hostAddr))             ips.add(hostAddr);
          }
        }
      }
    }
  }
 catch (  SocketException ignore) {
    return Collections.emptyList();
  }
  Collections.sort(ips);
  return ips;
}

public static synchronized Collection < String > allLocalIps ( ) { List < String > ips = new ArrayList < > ( 4 ) ; try { Enumeration < NetworkInterface > itfs = NetworkInterface . getNetworkInterfaces ( ) ; if ( itfs != null ) { for ( NetworkInterface itf : asIterable ( itfs ) ) { if ( ! itf . isLoopback ( ) ) { Enumeration < InetAddress > addrs = itf . getInetAddresses ( ) ; for ( InetAddress addr : asIterable ( addrs ) ) { String hostAddr = addr . getHostAddress ( ) ; if ( ! addr . isLoopbackAddress ( ) && ! ips . contains ( hostAddr ) ) ips . add ( hostAddr ) ; } } } } } catch ( SocketException ignore ) { return Collections . emptyList ( ) ; } Collections . sort ( ips ) ; return ips ; }
gets a list of all local non - loopback ips known to this jvm . note that this will include both ipv4 and ipv6 addresses ( even if one " resolves " into another ) . loopbacks will be skipped .
