I have the below code, that is basically printing something based on ipaddress.
private static void getInfo(String ipAddress) {
for (String cidr : myNetworkList) {
if (InetAddressValidator.getInstance().isValid(ipAddress)) {
if (cidr.equals(ipAddress)) {
//Do something
break;
}
}
else {
SubnetUtils subnetUtils = new SubnetUtils(cidr);
if (subnetUtils.getInfo().isInRange(ipAddress)) {
//Do something else
break;
}
}
}
}
The method works perfectly fine when I give a valid IP address as an argument such as - 17.151.126.28. If however, I give IP address in the CIDR notation, such as - 17.24.84.0/24, I get the below error -
Exception in thread "main" java.lang.IllegalArgumentException: Could not parse [17.24.84.0/24]
I have no idea how to resolve this. I read somewhere the issue is with Subnet since it doesn't support IpV4 addresses. I am not a networking expert, so I have no clue if the issue is with subnet, or if I should be using an alternate library?