code: public static long ipToLong(String ip) {
          if (!isValidIp(ip)) {
              throw new IllegalArgumentException("Invalid IP address: " + ip);
          }
  
          long result = 0;
          String[] ipArr = ip.split("\\.");
          for (int i = 3; i >= 0; i--) {
              long part = Long.parseLong(ipArr[3 - i]);
              result |= part << (i * 8);
          }
          return result;
      }
docs: IP address to long (e.g. 10.0.0.1 -> 167772161).
  
  @param ip
  @return