code: private boolean isAllowedAddress(String ipAddress) {
          if (allowedAddresses == null) {
              return false;
          }
  
          // IPv4
          int offset = ipAddress.lastIndexOf('.');
          if (offset == -1) {
              // IPv6
              offset = ipAddress.lastIndexOf(':');
              if (offset == -1) {
                  return false;
              }
          }
  
          String ipAddressClass = ipAddress.substring(0, offset + 1) + '*';
          return (allowedAddresses.contains(ipAddressClass) || allowedAddresses.contains(ipAddress));
      }
docs: Returns whether IP address is valid.
  
  @param ipAddress the IP address
  @return true if IP address is a valid; false otherwise