Class Subnet<Type>

A Respresentation of a Subnet

Example

import { network } from "@rjweb/utils"

const subnet = new network.Subnet('127.1/32')
subnet.type // 4

subnet.size() // 1n
subnet.first() // <IPAddress>
subnet.last() // <IPAddress>

for (const ip of subnet) {
console.log(ip.long())
}

Since

1.7.0

Supports

nodejs, browser

Type Parameters

  • Type extends 4 | 6 = 4 | 6

Constructors

  • Create a new Subnet

    Type Parameters

    • Type extends 4 | 6 = 4 | 6

    Parameters

    Returns Subnet<Type>

    Example

    import { network } from "@rjweb/utils"

    const subnet = new network.Subnet('127.0.0.1/24')
    subnet.isIPv4() // true

    subnet.size() // 255n
    subnet.first() // <IPAddress v4 127.0.0.0>
    subnet.last() // <IPAddress v4 127.0.0.255>

    for (const ip of subnet) {
    console.log(ip.long())
    }

    Since

    1.7.0

    Supports

    nodejs, browser

Properties

iFirst: IPAddress<4 | 6>
netmask: number

The Net Mask of the Subnet

Since

1.11.0

subnetmask: Type extends 4
    ? Type<Type> extends 6
        ? Uint8Array<ArrayBufferLike> | Uint16Array<ArrayBufferLike>
        : Uint8Array<ArrayBufferLike>
    : Uint16Array<ArrayBufferLike>

The Subnet Mask of the Subnet

Since

1.11.4

type: 4 | 6

Methods

  • Check if the Subnet includes another IP address or subnet

    Parameters

    Returns boolean

    Since

    1.11.0

  • Get the Size of the Subnet

    Returns bigint

    Since

    1.7.0