# Networks class · @imqueue/net

Source: https://imqueue.org/api/net/latest/net.networks/
Published: 2026-08-01
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/net 3.0.2 — generated reference, not hand-written

A CIDR membership set covering both address families — the entry point for most callers.

**Signature:**

```typescript
export declare class Networks 
```

## Remarks

Give it a mixed list of CIDR records and it sorts them into one [NetworkList](https://imqueue.org/api/net/latest/net.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()](https://imqueue.org/api/net/latest/net.networks.includes/) answers `false` for it — so a v4-only set safely answers questions about IPv6 addresses.

## Example


```typescript
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)](https://imqueue.org/api/net/latest/net.networks._constructor_/) |  | Builds a set from CIDR records of either family, or from previously packed buffers. |


## Properties


| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [ipv4](https://imqueue.org/api/net/latest/net.networks.ipv4/) | `readonly` | [NetworkList](https://imqueue.org/api/net/latest/net.networklist/) | The IPv4 networks, as a [NetworkList](https://imqueue.org/api/net/latest/net.networklist/) — reachable as `.ipv4`. |
| [ipv6](https://imqueue.org/api/net/latest/net.networks.ipv6/) | `readonly` | [NetworkList](https://imqueue.org/api/net/latest/net.networklist/) | The IPv6 networks, as a [NetworkList](https://imqueue.org/api/net/latest/net.networklist/) — reachable as `.ipv6`. |


## Methods


| Method | Modifiers | Description |
| --- | --- | --- |
| [includes(ip)](https://imqueue.org/api/net/latest/net.networks.includes/) |  | Whether an address falls inside any network in this set. |
| [toArray(canonical)](https://imqueue.org/api/net/latest/net.networks.toarray/) |  | Every stored network as CIDR records, IPv4 first. |
| [toIntRanges()](https://imqueue.org/api/net/latest/net.networks.tointranges/) |  | Every stored range as integer pairs, grouped by family. |
| [toJSON()](https://imqueue.org/api/net/latest/net.networks.tojson/) |  | The CIDR array, so `JSON.stringify` on this object yields the network set. |

