@terascope/ip-utils / utils/cidr-block / CIDRBlock
Class: CIDRBlock
Defined in: utils/cidr-block.ts:18
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
version | readonly | 4 | 6 | utils/cidr-block.ts:22 |
Methods
address()
address():
IPAddress
Defined in: utils/cidr-block.ts:131
The original input address (may differ from network address).
Returns
broadcast()
broadcast():
IPAddress
Defined in: utils/cidr-block.ts:182
IPv4 broadcast address (last IP in block). Throws for IPv6 CIDRs.
Returns
contains()
contains(
input):boolean
Defined in: utils/cidr-block.ts:208
Returns true if the given IP is within this CIDR block. The IP version must match the CIDR version exactly.
Parameters
| Parameter | Type |
|---|---|
input | string | IPAddress |
Returns
boolean
first()
first():
IPAddress
Defined in: utils/cidr-block.ts:136
Network address — first IP in block (all host bits 0).
Returns
firstUsable()
firstUsable():
IPAddress
Defined in: utils/cidr-block.ts:154
First usable host address. IPv4: network + 1, except /32 (single host). IPv6: network + 1, except /128 (single host).
Returns
last()
last():
IPAddress
Defined in: utils/cidr-block.ts:141
Last IP in block (all host bits 1).
Returns
lastUsable()
lastUsable():
IPAddress
Defined in: utils/cidr-block.ts:168
Last usable host address. IPv4: broadcast - 1, except /32 (returns broadcast). IPv6: same as last (no broadcast concept).
Returns
network()
network():
IPAddress
Defined in: utils/cidr-block.ts:194
IPv4 network address (first IP in block). Throws for IPv6 CIDRs.
Returns
toString()
toString():
string
Defined in: utils/cidr-block.ts:126
Returns
string
enclosing()
staticenclosing(ip1,ip2):CIDRBlock
Defined in: utils/cidr-block.ts:68
Return the smallest CIDR block that encloses both IP addresses. Both IPs must be the same version.
NOTE: The result is network-aligned and may extend beyond the input IPs. For example, enclosing(192.198.0.1, 192.198.0.254) → 192.198.0.0/24, which includes 192.198.0.0 and 192.198.0.255. This is a CIDR/routing operation — use IPRange for arbitrary range containment checks.
Parameters
| Parameter | Type |
|---|---|
ip1 | IPAddress |
ip2 | IPAddress |
Returns
CIDRBlock
from()
staticfrom(ip,prefix):CIDRBlock
Defined in: utils/cidr-block.ts:47
Build a CIDRBlock from an IPAddress and prefix length.
Parameters
| Parameter | Type |
|---|---|
ip | IPAddress |
prefix | number |
Returns
CIDRBlock
isCidr()
staticisCidr(input):0|4|6
Defined in: utils/cidr-block.ts:113
Parameters
| Parameter | Type |
|---|---|
input | string |
Returns
0 | 4 | 6
isValid()
staticisValid(input):input is string
Defined in: utils/cidr-block.ts:108
Parameters
| Parameter | Type |
|---|---|
input | unknown |
Returns
input is string
of()
staticof(cidr):CIDRBlock
Defined in: utils/cidr-block.ts:36
Parse "a.b.c.d/n" or "::1/128" CIDR notation. Throws if invalid.
Parameters
| Parameter | Type |
|---|---|
cidr | string |
Returns
CIDRBlock