简体   繁体   中英

SubnetUtils isInRange Method Return True - False Positive Issue

I create a method that have this code script :

SubnetUtils utils = new SubnetUtils("15.0.0.0/8");
        if (utils.getInfo().isInRange("170.2.1.1"))
        {
            // Do some code
        } 

the if statement returns true ! But the single ip isn't in range.

What am I doing wrong? Is there's another way to check if single ip in range?

Thanks

It's showing the correct result on ,y system. See the following image:

I also printed the min & max range:

System.out.println("lower address: " + utils.getInfo().getLowAddress());
System.out.println("higher address: " + utils.getInfo().getHighAddress());

I am using version 3.3 for SubnetUtils lib

在此处输入图片说明

SubnetUtils subnetUtils = new SubnetUtils("cidrRange");
**subnetUtils.setInclusiveHostCount(true);**
boolean withinRange = subnetUtils.getInfo().isInRange("ipAddress");

Reference : https://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/util/SubnetUtils.SubnetInfo.html#isInRange-java.lang.String-

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM