Apache SubnetInfo 用于环回地址

发布于 2024-11-10 00:29:22 字数 251 浏览 5 评论 0原文

使用 Apache Commons Net 库,为什么以下输出 CIDR 表示法 127.0.0.1/32 的 0 地址?我早就料到会有这样的结果,还是我误解了什么?地址127.0.0.1不在指定范围内吗?

SubnetInfo rangeInfo = new SubnetUtils("127.0.0.1/32").getInfo();
System.out.println(rangeInfo.getAddressCount());

Using the Apache Commons Net library, why does the following output 0 addresses for the CIDR notation 127.0.0.1/32 ? I'd have expected one, or am I misunderstanding something? Is the address 127.0.0.1 not in the specified range?

SubnetInfo rangeInfo = new SubnetUtils("127.0.0.1/32").getInfo();
System.out.println(rangeInfo.getAddressCount());

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云裳 2024-11-17 00:29:22

我还没有测试过,但似乎变量 rangeInfo 尚未设置。如果这只是一个拼写错误,这可能会为您提供正确的主机数量。

SubnetInfo info = new SubnetUtils("127.0.0.1/32").getInfo();
info.setInclusiveHostCount(true);
System.out.println(info.getAddressCount());

I haven't tested it yet, but it appears that the variable rangeInfo is not set. If that is just a typo, this may get you the correct number of hosts.

SubnetInfo info = new SubnetUtils("127.0.0.1/32").getInfo();
info.setInclusiveHostCount(true);
System.out.println(info.getAddressCount());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文