package
module
Version:
v1.0.2
Opens a new window with list of versions in this module.
Published: Jul 17, 2020
License: MIT
Opens a new window with license information.
Imports: 3
Opens a new window with list of imports.
Imported by: 2
Opens a new window with list of known importers.
README
¶
cidrmerge
Package cidrmerge merges IPv4 and IPv6 networks.
https://pkg.go.dev/github.com/thcyron/cidrmerge
Example
package main
import (
"fmt"
"net"
"github.com/thcyron/cidrmerge"
)
func main() {
_, ipNet1, _ := net.ParseCIDR("192.168.0.0/24")
_, ipNet2, _ := net.ParseCIDR("192.168.1.0/24")
merged := cidrmerge.Merge([]*net.IPNet{ipNet1, ipNet2})
fmt.Println(merged) // Prints: [192.168.0.0/23]
}
Documentation
¶
Package cidrmerge merges IPv4 and IPv6 networks.
package main
import (
"fmt"
"net"
"github.com/thcyron/cidrmerge"
)
func main() {
_, ipNet1, _ := net.ParseCIDR("192.168.0.0/24")
_, ipNet2, _ := net.ParseCIDR("192.168.1.0/24")
merged := cidrmerge.Merge([]*net.IPNet{ipNet1, ipNet2})
fmt.Println(merged)
}
Output:
[192.168.0.0/23]
Merge finds adjacent networks in ipNets and merges them. It handles
both IPv4 and IPv6 networks, even in the same slice.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.