IPAddressCheckerRange.java
package com.ziesemer.utils.web.addressFilter.conditions;
import java.net.InetAddress;
/**
* @author Mark A. Ziesemer
* <a href="http://www.ziesemer.com."><www.ziesemer.com></a>
*/
public class IPAddressCheckerRange implements IAddressChecker{
protected final byte[] beginAddress;
protected final byte[] endAddress;
public IPAddressCheckerRange(final byte[] beginAddress, final byte[] endAddress){
this.beginAddress = beginAddress;
this.endAddress = endAddress;
}
public boolean matches(final InetAddress ip, final String hostName) throws Exception{
if(ip == null){
return false;
}
return IPUtils.isInRange(beginAddress, endAddress, ip.getAddress());
}
/**
* <p>
* Returns a copy of the beginAddress checked against, primarily for unit testing.
* </p>
*/
public byte[] getBeginAddress(){
return beginAddress.clone();
}
/**
* <p>
* Returns a copy of the endAddress checked against, primarily for unit testing.
* </p>
*/
public byte[] getEndAddress(){
return endAddress.clone();
}
}