去 - 计算下方的CIDR一位的CIDR
ask
您如何计算下面提供的CIDR以下的CIDR?
给定:
网络cidr:(192.168.0.0/16)
想要结果
192.168.0.0.0.0/17,192.168.128.0/17
使用默认 net等软件包
软件包和 github.com/brotherpowers/ipsubnet
, github.com/seancfoley/ipaddress-go/ipaddr
没有得到所需的结果。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要将网络分为二,将前缀的长度增加一个。那给你下半部。要计算下半部分,请通过一个(省略为简洁的错误处理)来增加网络部分):
To split a network in two, increment the length of the prefix by one. That gives you the lower half. To compute the second half, increment the network part by one (error handling omitted for brevity):
https://go.dev/play/p/0HLqUK0RmVC
“使用默认网络软件包和github.com/brotherpowers/ipsubnet,github.com/seancfoley/ipaddress-go/ipaddr没有得到理想的结果
。用
github.com/seancfoley/ipaddress-go/ipaddr
(注意此代码也可与IPv6一起使用,并且前缀长度的任何更改):输出:输出:
"Using packages such as the default net package and github.com/brotherpowers/ipsubnet, github.com/seancfoley/ipaddress-go/ipaddr did not get the desired results."
Here is how to do it with
github.com/seancfoley/ipaddress-go/ipaddr
(note this code also works with IPv6 and any change in prefix length):Output: