Networks class

A CIDR membership set covering both address families — the entry point for most callers.

Signature:

export declare class Networks 

Remarks

Give it a mixed list of CIDR records and it sorts them into one NetworkList per family, then dispatches each lookup to the list matching the address it is asked about. That indirection exists because the two families cannot share a buffer: an IPv6 record is 32 bytes against IPv4's 8.

Lookups are O(log n) within a family. Instances are immutable, so extending a set means constructing a new one.

A family with no networks is left unset rather than empty, and Networks.includes() answers false for it — so a v4-only set safely answers questions about IPv6 addresses.

Example

const allowed = new Networks(['10.0.0.0/8', '2001:db8::/32']);

allowed.includes('10.1.2.3');     // true
allowed.includes('2001:db8::1');  // true
allowed.includes('8.8.8.8');      // false

Constructors

Constructor

Modifiers

Description

(constructor)(networks, networks6)

Builds a set from CIDR records of either family, or from previously packed buffers.

Properties

Property

Modifiers

Type

Description

ipv4

readonly

NetworkList

The IPv4 networks, as a NetworkList — reachable as .ipv4.

ipv6

readonly

NetworkList

The IPv6 networks, as a NetworkList — reachable as .ipv6.

Methods

Method

Modifiers

Description

includes(ip)

Whether an address falls inside any network in this set.

toArray(canonical)

Every stored network as CIDR records, IPv4 first.

toIntRanges()

Every stored range as integer pairs, grouped by family.

toJSON()

The CIDR array, so JSON.stringify on this object yields the network set.

Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.