protected int checkIPRange(){
  int retVal=0;
  String ipVersion;
  String ipType;
  Map<String,String> holdDetails;
  for (  String nextIP : IPRangeRange) {
    try {
      holdDetails=checkIPVersion(nextIP);
    }
 catch (    IllegalArgumentException e) {
      if (debug.warningEnabled()) {
        debug.warning("{}.checkIPRange: IP type could not be validated. IP={}",ADAPTIVE,nextIP,e);
      }
      continue;
    }
    ipVersion=holdDetails.get(IP_Version);
    ipType=holdDetails.get(IP_TYPE);
    if (ipVersion.equalsIgnoreCase(IP_V6) && ValidateIPaddress.isIPv6(clientIP)) {
      if (debug.messageEnabled()) {
        debug.message("{}.checkIPRange: {} --> {}",ADAPTIVE,clientIP,nextIP);
        debug.message("IP version is: {}",IP_V6);
        debug.message("Client IP is: {}",IPv6Address.fromString(clientIP));
      }
      if (ipType.equalsIgnoreCase("Range")) {
        String first=holdDetails.get(IP_START);
        String last=holdDetails.get(IP_END);
        IPv6AddressRange iPv6AddressRange=IPv6AddressRange.fromFirstAndLast(IPv6Address.fromString(first),IPv6Address.fromString(last));
        if (iPv6AddressRange.contains(IPv6Address.fromString(clientIP))) {
          retVal=IPRangeScore;
          break;
        }
      }
 else       if (ipType.equalsIgnoreCase("CIDR")) {
        IPv6Network iPv6Network=IPv6Network.fromString(nextIP);
        if (iPv6Network.contains(IPv6Address.fromString(clientIP))) {
          retVal=IPRangeScore;
          break;
        }
      }
 else {
        IPv6Address iPv6AddressNextIP=IPv6Address.fromString(nextIP);
        if (iPv6AddressNextIP.compareTo(IPv6Address.fromString(clientIP)) == 0) {
          retVal=IPRangeScore;
          break;
        }
      }
    }
 else     if (ipVersion.equalsIgnoreCase(IP_V4) && ValidateIPaddress.isIPv4(clientIP)) {
      if (debug.messageEnabled()) {
        debug.message("{}.checkIPRange: {} --> {}",ADAPTIVE,clientIP,nextIP);
        debug.message("IP version is: {}",IP_V4);
        debug.message("Client IP is: {}",clientIP);
      }
      IPRange theRange=new IPRange(nextIP);
      if (theRange.inRange(clientIP)) {
        retVal=IPRangeScore;
        break;
      }
    }
  }
  if (!IPRangeInvert) {
    retVal=IPRangeScore - retVal;
  }
  return retVal;
}

protected int checkIPRange ( ) { int retVal = 0 ; String ipVersion ; String ipType ; Map < String , String > holdDetails ; for ( String nextIP : IPRangeRange ) { try { holdDetails = checkIPVersion ( nextIP ) ; } catch ( IllegalArgumentException e ) { if ( debug . warningEnabled ( ) ) { debug . warning ( "{}.checkIPRange: IP type could not be validated. IP={}" , ADAPTIVE , nextIP , e ) ; } continue ; } ipVersion = holdDetails . get ( IP_Version ) ; ipType = holdDetails . get ( IP_TYPE ) ; if ( ipVersion . equalsIgnoreCase ( IP_V6 ) && ValidateIPaddress . isIPv6 ( clientIP ) ) { if ( debug . messageEnabled ( ) ) { debug . message ( "{}.checkIPRange: {} --> {}" , ADAPTIVE , clientIP , nextIP ) ; debug . message ( "IP version is: {}" , IP_V6 ) ; debug . message ( "Client IP is: {}" , IPv6Address . fromString ( clientIP ) ) ; } if ( ipType . equalsIgnoreCase ( "Range" ) ) { String first = holdDetails . get ( IP_START ) ; String last = holdDetails . get ( IP_END ) ; IPv6AddressRange iPv6AddressRange = IPv6AddressRange . fromFirstAndLast ( IPv6Address . fromString ( first ) , IPv6Address . fromString ( last ) ) ; if ( iPv6AddressRange . contains ( IPv6Address . fromString ( clientIP ) ) ) { retVal = IPRangeScore ; break ; } } else if ( ipType . equalsIgnoreCase ( "CIDR" ) ) { IPv6Network iPv6Network = IPv6Network . fromString ( nextIP ) ; if ( iPv6Network . contains ( IPv6Address . fromString ( clientIP ) ) ) { retVal = IPRangeScore ; break ; } } else { IPv6Address iPv6AddressNextIP = IPv6Address . fromString ( nextIP ) ; if ( iPv6AddressNextIP . compareTo ( IPv6Address . fromString ( clientIP ) ) == 0 ) { retVal = IPRangeScore ; break ; } } } else if ( ipVersion . equalsIgnoreCase ( IP_V4 ) && ValidateIPaddress . isIPv4 ( clientIP ) ) { if ( debug . messageEnabled ( ) ) { debug . message ( "{}.checkIPRange: {} --> {}" , ADAPTIVE , clientIP , nextIP ) ; debug . message ( "IP version is: {}" , IP_V4 ) ; debug . message ( "Client IP is: {}" , clientIP ) ; } IPRange theRange = new IPRange ( nextIP ) ; if ( theRange . inRange ( clientIP ) ) { retVal = IPRangeScore ; break ; } } } if ( ! IPRangeInvert ) { retVal = IPRangeScore - retVal ; } return retVal ; }
check to see if the ip address is within the ranges specified range can be in the form of : x . x . x . x / yy or x . x . x . x - y . y . y . y . or x : x : x : x : x : x : x : x / yy or x : x : x : x : x : x : x : x - y : y : y : y : y : y : y : y there can be multiple ranges passed in
