[英]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 ! if 语句返回 true ! But the single ip isn't in range.
但是单个ip不在范围内。
What am I doing wrong?我究竟做错了什么? Is there's another way to check if single ip in range?
是否有另一种方法来检查单个 ip 是否在范围内?
Thanks谢谢
It's showing the correct result on ,y system. 它在y系统上显示正确的结果。 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 lib使用版本3.3
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-参考: https ://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/util/SubnetUtils.SubnetInfo.html#isInRange-java.lang.String-
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.