Java check if IPv4 or IPv6 address is in a given subnet

Jan H picture Jan H · Jun 10, 2013 · Viewed 17.2k times · Source

How can I check if an IP address is in a given subnet? I was able to do this by using Apache Commons SubnetUtils (SubnetUtils.SubnetInfo.isInRange) but it does not support IPv6 yet.

Answer

Jan H picture Jan H · Jun 10, 2013

edazdarevic's CIDRUtils supports both IPv4 and IPv6. The example does not mention boolean isInRange(String ipAddress), but it is implemented!

Another option is java-ipv6, but it does not support IPv4 and requires JDK7.