code: public static InetAddress getLocalIP() {
          try {
              Collection<InterfaceAddress> ips = getAllIPAddresses();
              if (ips.size() > 0) {
                  return (InetAddress) ips.iterator().next().getAddress();
              } else {
                  return null;
              }
          } catch (Exception e) {
              return null;
          }
      }
docs: Retrieves the IP address of the local computer:
  - If there exists an interface different from "loopback" it will never return "127.0.0.1"
  - If there exists multiple network interfaces, the first one will be returned