public static int getCidrPrefixLength(String cidr) {
        SubnetUtils subnetUtils = new SubnetUtils(cidr);
        subnetUtils.setInclusiveHostCount(true);
        // 2^(32 - prefixLength) = addressCount,
        // so prefixLength = 32 - log2(addressCount) = 32 - (63 - leadingZeros(addressCount)) = leadingZeros(addressCount) - 31
        return Long.numberOfLeadingZeros(subnetUtils.getInfo().getAddressCountLong()) - 31;
    }
@Test
    public void testGetCidrPrefixLength() {
        for (int i = 0; i <= 32; i++) {
            String addr = "192.168.0.1/" + i;
            assertThat(NetUtils.getCidrPrefixLength(addr)).isEqualTo(i);
        }
    }