Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

netip

The netip module wraps Go's immutable net/netip address and prefix values. It performs parsing and address calculations without opening network sockets.

import "x/net/netip"

var addr = netip.Addr("192.168.1.10")
var network = netip.Prefix("192.168.1.5/24")
print(addr.is_private)
print(network.masked())
print(network.contains(addr))

Addr

Construct an address with Addr(text). Its members are bits, bytes, zone, is4, is6, is_loopback, is_multicast, is_private, is_unspecified, is_link_local_unicast, and is_link_local_multicast. Methods next(), prev(), and unmap() return new Addr values.

Addr values compare in Go's canonical address order. Moving beyond the first or last address with prev() or next() raises ValueError.

Prefix

Construct a prefix with Prefix(text). It exposes addr, bits, and is_single_ip, plus these methods:

MethodReturnsDescription
contains(addr)boolReport whether the address lies in the prefix
overlaps(prefix)boolReport whether two prefixes overlap
masked()PrefixReturn the canonical network prefix