RepositoryGoCNChina
3th1nk

3th1nk/cidr

Go library for CIDR: parse, sort, split & merge IP segments, overlap/subnet checks, collapse & range ops, host & mask math, netip interop (IPv4/IPv6)

95stars
19forks
0issues
2views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: cidr

#1 Repository of the month

1
TINIX TRENDING·Topic: ip-address

#1 Repository of the month

1
TINIX TRENDING·Topic: iprange

#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.

RepositoryGo
seancfoley/ipaddress-go

Go library for handling IP addresses and subnets, both IPv4 and IPv6

118
Nov 5, 2026
RepositoryGo
avelino/awesome-go

A curated list of awesome Go frameworks, libraries and software

197.2k
Dec 2, 2026
RepositoryGo
ollama/ollama

Get up and running with Inkling, Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

188.9k
Dec 2, 2026
RepositoryHTML
itbdw/ip-database

免费IP离线数据库,支持IPV4+IPV6 ,国家、省、市、县、运营商

1.5k
Dec 1, 2023
RepositoryTypeScript
beaugunderson/ip-address

💻 a library for parsing and manipulating IPv4 and IPv6 addresses in JavaScript

636
Nov 28, 2026
RepositoryC#
lduchosal/ipnetwork

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

526
Nov 16, 2026
RepositoryGo
golang/go

The Go programming language

140.0k
Dec 1, 2026
RepositoryGo
moby/moby

The Moby Project - a collaborative project for the container ecosystem to assemble container-based systems

72.3k
Nov 26, 2026
RepositoryGo
traefik/traefik

The Cloud Native Application Proxy

65.9k
Dec 2, 2026