将IP分组为最小的CIDR范围
我正在尝试使用大量连续的IP地址,并将它们分组为CIDR范围。目的是最终以最小数量的CIDR范围。
到目前为止,我的想法是按顺序通过IP,创建最大的CIDR范围,然后从下一个连续的IP开始,然后再次进行。
这似乎应该导致最小的CIDR范围,但是,我想到了一个边缘案例,我希望有人能够确认是否真的会发生这种边缘情况。
说我们有一组连续的IP。在我的方法(使最大的组并继续前进)上,我们确定以下分组(每个组代表有效的CIDR范围):
(med), (med), (small)
但是,想象一下此分组也可以:
(small), (large)
请注意,第二个分组更好,因为它仅需要它2范围,而另一个需要3。我提出的方法不会发现该分组。这是可能的(或某些相似的)场景吗?如果是这样,有人可以提供例子?
I'm trying to take large sets of consecutive IP addresses and group them into CIDR ranges. The objective is to end up with the smallest number of CIDR ranges possible.
My idea so far has been to move through the IPs in order, creating the largest CIDR range possible, then starting at the next consecutive ip, and doing the same again.
This seems like it should lead to the smallest possible set of CIDR ranges, however, I thought of an edge case and I was hoping someone might be able to confirm whether this edge case can actually occur.
Say we have a set of n consecutive IPs. On my method (make the largest group and move on), we identify the following grouping (where each group represents a valid CIDR range):
(med), (med), (small)
However, imagine this grouping is also possible:
(small), (large)
Notice that this second grouping is better in that it requires only 2 ranges whereas the other requires 3. The method I proposed won't discover this grouping. Is this (or some relevantly similar) kind of scenario possible? If so could someone offer an example?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论