1 2 3 4 5 6 7 8 9 10 11 12 13 14
| cidrs := []*net.IPNet{ &net.IPNet{IP: net.ParseIP(“192.168.0.0”), Mask: net.CIDRMask(24, 32)}, &net.IPNet{IP: net.ParseIP(“192.168.1.0”), Mask: net.CIDRMask(24, 32)}, &net.IPNet{IP: net.ParseIP(“192.168.2.0”), Mask: net.CIDRMask(24, 32)}, &net.IPNet{IP: net.ParseIP(“192.168.1.0”), Mask: net.CIDRMask(25, 32)}, &net.IPNet{IP: net.ParseIP(“192.168.1.128”), Mask: net.CIDRMask(25, 32)}, } mergedCIDRs := MergeCIDRs(cidrs) for _, c := range mergedCIDRs { fmt.Printf(“%s\n”, c.String()) } 输出结果为: 192.168.0.0/23 192.168.2.0/24
|