seancfoley/ipaddress-go
Go library for handling IP addresses and subnets, both IPv4 and IPv6
Featured achievements
The project's latest awards
#1 Repository of the week
#1 Repository of the week
#1 Repository of the week
ipaddress-go
Go library for handling IP addresses and subnets, both IPv4 and IPv6
IP address and network manipulations, CIDR, address and subnet operations, address ranges, iterators, containment checks, longest prefix match, subnetting, address tries, address collections, and more, with polymorphic code
| Version | Notes |
|---|---|
| 1.2.1 | Requires Go 1.12 or higher |
| 1.4.1 | Requires Go 1.13 or higher |
| 1.7.1 | Requires Go 1.18 or higher |
In your go.mod file:
require github.com/seancfoley/ipaddress-go v1.7.1
In your source file:
import "github.com/seancfoley/ipaddress-go/ipaddr"
Packaged as a Linux Fedora rpm and as a Linux Debian, available from Ubuntu
Also available as a Java library from the IPAddress repository
Getting Started
starting with address or subnet strings
import "github.com/seancfoley/ipaddress-go/ipaddr"
ipv6AddrStr := ipaddr.NewIPAddressString("a:b:c:d::a:b/64")
if ipAddr, err := ipv6AddrStr.ToAddress(); err != nil {
// err.Error() has validation error
} else {
// use the address
}
...or avoid errors, checking for nil:
str := ipaddr.NewIPAddressString("a:b:c:d:e-f:f:1.2-3.3.4/64")
addr := str.GetAddress()
if addr != nil {
// use address
}
starting with host name strings
hostStr := "[::1]"
host := ipaddr.NewHostName(hostStr)
err := host.Validate()
if err == nil {
if host.IsAddress() {
fmt.Println("address: " + host.AsAddress().String())
} else {
fmt.Println("host name: " + host.String())
}
// use host
} else {
fmt.Println(err.Error())
}
Similar Projects
Discover other similar projects and AI models.
Go library for CIDR: parse, sort, split & merge IP segments, overlap/subnet checks, collapse & range ops, host & mask math, netip interop (IPv4/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
PHP library for IPv4 subnet calculations, CIDR operations, and network planning.