code: static InetAddress getNIFirstAddress(int niIndex) throws SocketException {
          if (niIndex > 0) {
              NetworkInterface networkInterface = NetworkInterface.getByIndex(niIndex);
              Enumeration<InetAddress> addressesEnum = networkInterface.getInetAddresses();
              if (addressesEnum.hasMoreElements()) {
                  return addressesEnum.nextElement();
              }
          }
          return InetAddress.anyLocalAddress();
      }
docs: Return the first address bound to NetworkInterface with given ID.
  In case of niIndex == 0 or no address return anyLocalAddress