seancfoley/ipaddress-go

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

Go

119

208 commits

updated Sep 10, 2026

See the code

README

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

Docs

Code Examples

Godoc Go Reference

List of Users

VersionNotes
1.2.1Requires Go 1.12 or higher
1.4.1Requires Go 1.13 or higher
1.8.3Requires Go 1.18 or higher
1.8.4Requires Go 1.24 or higher

In your go.mod file:
require github.com/seancfoley/ipaddress-go v1.8.4

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())
}
cidr
go
golang
golang-library
golang-module
golang-package
ip-address
ipaddress
ipv4
ipv4-address
ipv4-network
ipv4-subnetting
ipv6
ipv6-address
ipv6-network
ipv6-subnetting
mac-address
subnet
subnets
subnetting

seancfoley/ipaddress-go

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

Go

119

208 commits

updated Sep 10, 2026

See the code

README

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

Docs

Code Examples

Godoc Go Reference

List of Users

VersionNotes
1.2.1Requires Go 1.12 or higher
1.4.1Requires Go 1.13 or higher
1.8.3Requires Go 1.18 or higher
1.8.4Requires Go 1.24 or higher

In your go.mod file:
require github.com/seancfoley/ipaddress-go v1.8.4

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())
}
cidr
go
golang
golang-library
golang-module
golang-package
ip-address
ipaddress
ipv4
ipv4-address
ipv4-network
ipv4-subnetting
ipv6
ipv6-address
ipv6-network
ipv6-subnetting
mac-address
subnet
subnets
subnetting

Project health

Overall

3.5/10

Maintained

10/10

Code review

0/10
OpenSSF Scorecard

Latest release

v1.8.4 · Sep 8, 2026

Releases this year

5

Significant stargazers

Jesús Rubio

370 followers · starred Sep 2023

Jason Wilder

1,480 followers · starred Jun 2025