예제 #1
0
  public String getForeignSource(InetAddress address) {
    getReadLock().lock();
    try {
      LOG.debug(
          "Looking for matching foreign source specific IP or IP range with address: {}...",
          address);

      List<Specific> specificCollection = getConfiguration().getSpecificCollection();
      for (Specific specific : specificCollection) {
        String ipAddr = specific.getContent();

        if (ipAddr.equals(InetAddressUtils.str(address))) {

          String foreignSource = specific.getForeignSource();
          LOG.debug(
              "Matched foreign source {} matching address: {} against specific {}.",
              foreignSource,
              address,
              ipAddr);
          return foreignSource;
        }
      }

      final byte[] laddr = address.getAddress();

      List<IncludeRange> includeRangeCollection = getConfiguration().getIncludeRangeCollection();
      for (IncludeRange range : includeRangeCollection) {

        if (InetAddressUtils.isInetAddressInRange(laddr, range.getBegin(), range.getEnd())) {

          String foreignSource = range.getForeignSource();
          LOG.debug(
              "Found foreign source {} with address {} in the range begin: {} and end: {}.",
              foreignSource,
              address,
              range.getBegin(),
              range.getEnd());
          return foreignSource;
        }
      }

      List<IncludeUrl> includeUrlCollection = getConfiguration().getIncludeUrlCollection();
      for (IncludeUrl includeUrl : includeUrlCollection) {
        String ipAddr = includeUrl.getContent();
        if (ipAddr.equals(InetAddressUtils.str(address))) {

          String foreignSource = includeUrl.getForeignSource();
          LOG.debug(
              "Matched foreign source {} matching address: {} in specified URL.",
              foreignSource,
              address);
          return foreignSource;
        }
      }

      return getConfiguration().getForeignSource();
    } finally {
      getReadLock().unlock();
    }
  }
예제 #2
0
  /**
   * isExcluded
   *
   * @param address a {@link java.net.InetAddress} object.
   * @return a boolean.
   */
  public boolean isExcluded(final InetAddress address) {
    getReadLock().lock();
    try {
      final List<ExcludeRange> excludeRange = getConfiguration().getExcludeRangeCollection();
      if (excludeRange != null) {
        final byte[] laddr = address.getAddress();

        for (final ExcludeRange range : excludeRange) {
          if (InetAddressUtils.isInetAddressInRange(laddr, range.getBegin(), range.getEnd())) {
            return true;
          }
        }
      }
      return false;
    } finally {
      getReadLock().unlock();
    }
  }
예제 #3
0
 /**
  * This method may be used to determine if the specified IP address is contained within the IP
  * address range.
  *
  * @param ipAddr IP address (String) to compare
  * @return 'true' if the specified IP address falls within the IP address range. 'false'
  *     otherwise.
  */
 boolean contains(String ipAddr) throws java.net.UnknownHostException {
   return InetAddressUtils.isInetAddressInRange(ipAddr, m_begin, m_end);
 }
예제 #4
0
 /**
  * This method may be used to determine if the specified IP address is contained within the IP
  * address range.
  *
  * @param ipAddr IP address (InetAddress) to compare
  * @return 'true' if the specified IP address falls within the IP address range. 'false'
  *     otherwise.
  */
 boolean contains(InetAddress ipAddr) {
   return InetAddressUtils.isInetAddressInRange(ipAddr.getAddress(), m_begin, m_end);
 }