China3th1nk/cidr
Go library for CIDR: parse, sort, split & merge IP segments, overlap/subnet checks, collapse & range ops, host & mask math, netip interop (IPv4/IPv6)
Featured achievements
The project's latest awards
#1 Repository of the month
#1 Repository of the month
#1 Repository of the month
CIDR
Features
- easy to iterate through each ip in segment
- check ipv4 or ipv6 segment
- check whether segment contain ip
- segments sort、split、merge
- ip incr & decr
- ip compare
Code Example
package main
import (
"fmt"
"github.com/3th1nk/cidr"
)
func main() {
// parses a network segment as a CIDR
c, _ := cidr.Parse("192.168.1.0/28")
fmt.Println("network:", c.Network(), "broadcast:", c.Broadcast(), "mask", net.IP(c.Mask()))
// ip range
fmt.Println("ip range:", c.StartIP(), c.EndIP())
// iterate through each ip
fmt.Println("ip total:", c.IPCount())
c.Each(func(ip string) bool {
fmt.Println("\t", ip)
return true
})
c.EachFrom("192.168.1.10", func(ip string) bool {
fmt.Println("\t", ip)
return true
})
fmt.Println("subnet plan based on the subnets num:")
cs, _ := c.SubNetting(cidr.MethodSubnetNum, 4)
for _, c := range cs {
fmt.Println("\t", c.String())
}
fmt.Println("subnet plan based on the hosts num:")
cs, _ = c.SubNetting(cidr.MethodHostNum, 4)
for _, c := range cs {
fmt.Println("\t", c.String())
}
fmt.Println("merge network:")
c, _ = cidr.SuperNetting([]string{
"2001:db8::/66",
"2001:db8:0:0:8000::/66",
"2001:db8:0:0:4000::/66",
"2001:db8:0:0:c000::/66",
})
fmt.Println("\t", c.String())
}
Similar Projects
Discover other similar projects and AI models.
Go library for handling IP addresses and subnets, both IPv4 and IPv6
Get up and running with Inkling, Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.
💻 a library for parsing and manipulating IPv4 and IPv6 addresses in JavaScript
IPNetwork command line and C# library take care of complex network, IP, IPv4, IPv6, netmask, CIDR, subnet, subnetting, supernet, and supernetting calculation for .NET developers. It works with IPv4 as well as IPv6, is written in C#, has a light and clean API, and is fully unit-tested
The Moby Project - a collaborative project for the container ecosystem to assemble container-based systems