What you are asking is the IP address in the given cidr range. You can write your own code to find out the beginning and end of cidr and see if the IP address falls into this range, or just use Apache Commons Net .
The SubnetUtils class does exactly what you want:
String cidrRange = "1.232.12.0/20"; String addr = "1.232.12.3"; SubnetUtils utils = new SubnetUtils(cidrRange); boolean isInRange = utils.getInfo().isInRange(addr);
source share