code: public static InetAddress getLocalHost() throws UnknownHostException {
          try {
              final InetAddress is = InetAddress.getLocalHost();
              if (!is.isLoopbackAddress()) {
                  return is;
              }
          } catch (final UnknownHostException e) {
              // This can happen in odd cases like when using network cards.
              // Continue to try via UDP.
          }
  
          return getLocalHostViaUdp();
      }
docs: Many Linux systems typically return 127.0.0.1 as the localhost address
  instead of the address assigned on the local network. It has to do with
  how localhost is defined in /etc/hosts. This method creates a quick
  UDP socket and gets the local address for the socket on Linux systems
  to get around the problem. This can also happen on OSX in newer
  versions of the OS.
  
  @return The local network address in a cross-platform manner.
  @throws UnknownHostException If the host is considered unknown for
  any reason.