cidrmerge

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2020 License: MIT Imports: 3 Imported by: 2

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

Overview

Package cidrmerge merges IPv4 and IPv6 networks.

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)
}
Output:
[192.168.0.0/23]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Merge

func Merge(ipNets []*net.IPNet) []*net.IPNet

Merge finds adjacent networks in ipNets and merges them. It handles both IPv4 and IPv6 networks, even in the same slice.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL