@eryx/ip Module

JSON

Summary

Classes

version: number
_octets: { number }
_int: number
IPv4Address:toBytes()buffer
version: number
_hextets: { number }
IPv6Address:toBytes()buffer
IPv6Address:scope()"interface-local" | "link-local" | "global"
version: number
_prefix: number
_network: number
IPv4Network:subnets(newPrefix: number?)(() → IPv4Network?)
version: number
_prefix: number
_network: { number }
IPv6Network:subnets(newPrefix: number?)(() → IPv6Network?)
address: IPv4Address
network: IPv4Network
_prefix: number
address: IPv6Address
network: IPv6Network
_prefix: number
version: number
_segments: { { start: number, finish: number } }
IPv4Range:iter()(() → IPv4Address?)
version: number
_segments: { { start: { number }, finish: { number } } }
IPv6Range:iter()(() → IPv6Address?)

Functions

ip.isIPv4(source: string)boolean
ip.isIPv6(source: string)boolean
ip.sortIPv4(values: { IPv4Address | string }){ IPv4Address }
ip.sortIPv6(values: { IPv6Address | string }){ IPv6Address }

API Reference

Classes

IPv4Address

Represents an IPv4 address.

Properties

version: number

IP version number (4).

_octets: { number }

IPv4 octets in network order.

_int: number

Packed 32-bit integer representation.

IPv4Address.sort

Sort a collection of IPv4 address values.

IPv4Address.sort(values: { IPv4Address | string }){ IPv4Address }

Parameters

values: { IPv4Address | string }

IPv4Address instances or parseable IPv4 strings.

Returns

Parsed and sorted IPv4 addresses.

IPv4Address.parse

Parse an IPv4 address string with optional parse options.

IPv4Address.parse(source: string, options: ParseOptions?)IPv4Address?

Parameters

source: string

IPv4 address text to parse.

options: ParseOptions?

Optional parse behavior flags.

Returns

Parsed IPv4Address when the input is valid.

IPv4Address.fromOctets

IPv4 Constructors

IPv4Address.fromOctets(octets: { number })IPv4Address

IPv4Address.fromInteger

Create an IPv4Address from a 32-bit integer.

IPv4Address.fromInteger(val: number)IPv4Address

Parameters

val: number

Raw integer or packed bytes used to construct an address.

Returns

IPv4Address built from the packed integer.

IPv4Address.fromBytes

Create an IPv4Address from a 4-byte buffer or byte array.

IPv4Address.fromBytes(val: buffer | { number })IPv4Address

Parameters

val: buffer | { number }

Raw integer or packed bytes used to construct an address.

Returns

IPv4Address built from 4-byte input.

IPv4Address.fromPacked

Create an IPv4Address from packed byte input.

IPv4Address.fromPacked(val: buffer | { number })IPv4Address

Parameters

val: buffer | { number }

Buffer or byte array containing exactly four bytes.

Returns

Parsed IPv4Address from packed input.

IPv4Address:__string

Return a canonical IPv4 string

IPv4Address:__string()string

IPv4Address:reverseUri

Return the PTR/arpa form of the IP

IPv4Address:reverseUri()string

IPv4Address:toInteger

Pack the four octets into a 32 bit integer

IPv4Address:toInteger()number

IPv4Address:toBytes

Pack the four octets into four bytes in a buffer

IPv4Address:toBytes()buffer

IPv4Address:toPacked

Return packed IPv4 bytes for this address. @param self Current IPv4Address instance.

IPv4Address:toPacked()buffer

Returns

buffer

containing four network-order bytes.

IPv4Address:isPrivate

Return true for RFC1918 private IPv4 ranges. @param self Current object instance on which the method operates.

IPv4Address:isPrivate()boolean

Returns

result indicating whether the condition is met.

IPv4Address:ipPublic

Return true when the IPv4 address is globally reachable. @param self Current object instance on which the method operates.

IPv4Address:ipPublic()boolean

Returns

result indicating whether the condition is met.

IPv4Address:isLoopback

Return true for 127.0.0.0/8 loopback addresses. @param self Current object instance on which the method operates.

IPv4Address:isLoopback()boolean

Returns

result indicating whether the condition is met.

IPv4Address:isMulticast

Return true for 224.0.0.0/4 multicast addresses. @param self Current object instance on which the method operates.

IPv4Address:isMulticast()boolean

Returns

result indicating whether the condition is met.

IPv4Address:isLinkLocal

Return true for 169.254.0.0/16 link-local addresses. @param self Current object instance on which the method operates.

IPv4Address:isLinkLocal()boolean

Returns

result indicating whether the condition is met.

IPv4Address:isUnspecified

Return true for 0.0.0.0. @param self Current object instance on which the method operates.

IPv4Address:isUnspecified()boolean

Returns

result indicating whether the condition is met.

IPv4Address:isReserved

Return true for reserved Class E IPv4 addresses. @param self Current object instance on which the method operates.

IPv4Address:isReserved()boolean

Returns

result indicating whether the condition is met.

IPv4Address:isDocumentation

Return true for TEST-NET documentation ranges. @param self Current object instance on which the method operates.

IPv4Address:isDocumentation()boolean

Returns

result indicating whether the condition is met.

IPv4Address:isBenchmarking

Return true for IPv4 benchmarking ranges. @param self Current object instance on which the method operates.

IPv4Address:isBenchmarking()boolean

Returns

result indicating whether the condition is met.

IPv4Address:isShared

Return true for shared CGNAT space (100.64.0.0/10). @param self Current object instance on which the method operates.

IPv4Address:isShared()boolean

Returns

result indicating whether the condition is met.

IPv4Address:isGlobal

Return true when IPv4 address is considered globally reachable. @param self Current object instance on which the method operates.

IPv4Address:isGlobal()boolean

Returns

result indicating whether the condition is met.

IPv4Address:category

TODO: Replace string with a union of all categories (loopback, multicast, LL, reserved, etc)

Return a coarse category label describing this IPv4 address. @param self Current object instance on which the method operates.

IPv4Address:category()string

Returns

representation or textual result.

IPv4Address:isBroadcast

Return true for 255.255.255.255. @param self Current object instance on which the method operates.

IPv4Address:isBroadcast()boolean

Returns

result indicating whether the condition is met.

IPv4Address:inNetwork

Return true if this IPv4 address is inside the given network. @param self Current object instance on which the method operates.

IPv4Address:inNetwork(net: IPv4Network)boolean

Parameters

Network to test membership, overlap, or containment against.

Returns

result indicating whether the condition is met.

IPv4Address:next

Return the next IPv4 address. @param self Current object instance on which the method operates.

IPv4Address:next()IPv4Address

Returns

Next IPv4 address value.

IPv4Address:previous

Return the previous IPv4 address. @param self Current object instance on which the method operates.

IPv4Address:previous()IPv4Address

Returns

Previous IPv4 address value.

IPv4Address:toIPv6Mapped

Return the IPv4-mapped IPv6 form of this IPv4 address. @param self Current object instance on which the method operates.

IPv4Address:toIPv6Mapped()IPv6Address

Returns

IPv4-mapped IPv6 equivalent of this address.

IPv6Address

Represents an IPv6 address.

Properties

version: number

IP version number (6).

_hextets: { number }

IPv6 hextets in network order.

IPv6Address.sort

Sort a collection of IPv6 address values.

IPv6Address.sort(values: { IPv6Address | string }){ IPv6Address }

Parameters

values: { IPv6Address | string }

IPv6Address instances or parseable IPv6 strings.

Returns

Parsed and sorted IPv6 addresses.

IPv6Address.parse

Parse an IPv6 address string with optional parse options.

IPv6Address.parse(source: string, options: ParseOptions?)IPv6Address?

Parameters

source: string

IPv6 address text to parse.

options: ParseOptions?

Optional parse behavior flags.

Returns

Parsed IPv6Address when the input is valid.

IPv6Address.fromBytes

IPv6 Constructors

IPv6Address.fromBytes(val: buffer | { number })IPv6Address

IPv6Address.fromPacked

Create an IPv6Address from packed byte input.

IPv6Address.fromPacked(val: buffer | { number })IPv6Address

Parameters

val: buffer | { number }

Buffer or byte array containing exactly sixteen bytes.

Returns

Parsed IPv6Address from packed input.

IPv6Address.fromInteger

Create an IPv6Address from a non-negative integer value.

IPv6Address.fromInteger(val: number | string)IPv6Address

Parameters

val: number | string

Number or decimal string representation of a 128-bit integer.

Returns

Parsed IPv6Address from integer input.

IPv6Address:__string

Return a canonical IPv6 string (compressed)

IPv6Address:__string()string

IPv6Address:compressed

Return the fully compressed IPv6

IPv6Address:compressed()string

IPv6Address:expanded

Return the fully expanded IPv6

IPv6Address:expanded()string

IPv6Address:toUriHost

Return [compressed]

IPv6Address:toUriHost()string

IPv6Address:reverseUri

Return the PTR/arpa form of the IP

IPv6Address:reverseUri()string

IPv6Address:toBytes

Pack the bytes into a buffer

IPv6Address:toBytes()buffer

IPv6Address:toPacked

Return packed IPv6 bytes for this address. @param self Current IPv6Address instance.

IPv6Address:toPacked()buffer

Returns

buffer

containing sixteen network-order bytes.

IPv6Address:toInteger

Return the integer representation of this IPv6 address. @param self Current IPv6Address instance.

IPv6Address:toInteger()string

Returns

Decimal string representing the 128-bit address value.

IPv6Address:isPrivate

Return true for private (unique local) IPv6 addresses. @param self Current object instance on which the method operates.

IPv6Address:isPrivate()boolean

Returns

result indicating whether the condition is met.

IPv6Address:ipPublic

Return true when the IPv6 address is globally reachable. @param self Current object instance on which the method operates.

IPv6Address:ipPublic()boolean

Returns

result indicating whether the condition is met.

IPv6Address:isLoopback

Return true for ::1. @param self Current object instance on which the method operates.

IPv6Address:isLoopback()boolean

Returns

result indicating whether the condition is met.

IPv6Address:isMulticast

Return true for ff00::/8 multicast addresses. @param self Current object instance on which the method operates.

IPv6Address:isMulticast()boolean

Returns

result indicating whether the condition is met.

IPv6Address:isLinkLocal

Return true for fe80::/10 link-local addresses. @param self Current object instance on which the method operates.

IPv6Address:isLinkLocal()boolean

Returns

result indicating whether the condition is met.

IPv6Address:isUnspecified

Return true for ::. @param self Current object instance on which the method operates.

IPv6Address:isUnspecified()boolean

Returns

result indicating whether the condition is met.

IPv6Address:isReserved

Return true for reserved IPv6 blocks (placeholder). @param self Current object instance on which the method operates.

IPv6Address:isReserved()boolean

Returns

result indicating whether the condition is met.

IPv6Address:isDocumentation

Return true for 2001:db8::/32 documentation space. @param self Current object instance on which the method operates.

IPv6Address:isDocumentation()boolean

Returns

result indicating whether the condition is met.

IPv6Address:isBenchmarking

Return true for IPv6 benchmarking space. @param self Current object instance on which the method operates.

IPv6Address:isBenchmarking()boolean

Returns

result indicating whether the condition is met.

IPv6Address:isShared

Return true for shared IPv6 ranges (placeholder). @param self Current object instance on which the method operates.

IPv6Address:isShared()boolean

Returns

result indicating whether the condition is met.

IPv6Address:isGlobal

Return true when IPv6 address is considered globally reachable. @param self Current object instance on which the method operates.

IPv6Address:isGlobal()boolean

Returns

result indicating whether the condition is met.

IPv6Address:category

TODO: Replace string with a union of all categories (loopback, multicast, LL, reserved, etc)

Return a coarse category label describing this IPv6 address. @param self Current object instance on which the method operates.

IPv6Address:category()string

Returns

representation or textual result.

IPv6Address:isUniqueLocal

Return true for fc00::/7 unique local addresses. @param self Current object instance on which the method operates.

IPv6Address:isUniqueLocal()boolean

Returns

result indicating whether the condition is met.

IPv6Address:isIPv4Mapped

Return true if this is an IPv4-mapped IPv6 address. @param self Current object instance on which the method operates.

IPv6Address:isIPv4Mapped()boolean

Returns

result indicating whether the condition is met.

IPv6Address:isIPv4Compatible

Return true if this is an IPv4-compatible IPv6 address. @param self Current object instance on which the method operates.

IPv6Address:isIPv4Compatible()boolean

Returns

result indicating whether the condition is met.

IPv6Address:scope

TODO: Expand return enum

Return a coarse IPv6 scope classification. @param self Current object instance on which the method operates.

IPv6Address:scope()"interface-local" | "link-local" | "global"

Returns

"interface-local" | "link-local" | "global"

"link-local" | "global" Derived scope classification for this IPv6 address.

IPv6Address:getEmbeddedIPv4

Extract embedded IPv4 address from mapped/compatible IPv6 forms. @param self Current object instance on which the method operates.

IPv6Address:getEmbeddedIPv4()IPv4Address?

Returns

Embedded IPv4 address when present, otherwise nil.

IPv6Address:toIPv4

Convert mapped/compatible IPv6 addresses back to IPv4. @param self Current IPv6Address instance.

IPv6Address:toIPv4()IPv4Address?

Returns

Extracted IPv4Address when conversion is possible.

IPv6Address:is6to4

Return true for 6to4 IPv6 addresses (2002::/16). @param self Current IPv6Address instance.

IPv6Address:is6to4()boolean

Returns

True when the address belongs to 6to4 space.

IPv6Address:isTeredo

Return true for Teredo IPv6 addresses (2001:0000::/32). @param self Current IPv6Address instance.

IPv6Address:isTeredo()boolean

Returns

True when the address belongs to Teredo space.

IPv6Address:inNetwork

Return true if this IPv6 address is inside the given network. @param self Current object instance on which the method operates.

IPv6Address:inNetwork(net: IPv6Network)boolean

Parameters

Network to test membership, overlap, or containment against.

Returns

result indicating whether the condition is met.

IPv6Address:next

Return the next IPv6 address. @param self Current object instance on which the method operates.

IPv6Address:next()IPv6Address

Returns

Next IPv6 address value.

IPv6Address:previous

Return the previous IPv6 address. @param self Current object instance on which the method operates.

IPv6Address:previous()IPv6Address

Returns

Previous IPv6 address value.

IPv4Network

Represents an IPv4 CIDR network.

Properties

version: number

IP version number (4).

_prefix: number

CIDR prefix length.

_network: number

Packed network address as 32-bit integer.

IPv4Network.smallestContaining

Return the smallest IPv4 network containing both addresses.

IPv4Network.smallestContaining(a: IPv4Address, b: IPv4Address)IPv4Network

Parameters

First IPv4 address endpoint.

Second IPv4 address endpoint.

Returns

Minimal IPv4 CIDR block that covers both addresses.

IPv4Network.parse

Parse an IPv4 CIDR network string with optional parse options.

IPv4Network.parse(source: string, options: ParseOptions?)IPv4Network?

Parameters

source: string

IPv4 network text to parse.

options: ParseOptions?

Optional parse behavior flags.

Returns

Parsed IPv4Network when the input is valid.

IPv4Network.mergeNetworks

Merge and collapse overlapping/adjacent IPv4 networks.

IPv4Network.mergeNetworks(networks: { IPv4Network | string }){ IPv4Network }

Parameters

networks: { IPv4Network | string }

IPv4Network instances or parseable IPv4 CIDR strings.

Returns

Minimal merged set of IPv4 networks.

IPv4Network:networkAddress

IPv4 Network =====
IPv4Network:networkAddress()IPv4Address

IPv4Network:broadcastAddress

Return the broadcast address of this IPv4 CIDR block. @param self Current object instance on which the method operates.

IPv4Network:broadcastAddress()IPv4Address

Returns

Broadcast address for this IPv4 network.

IPv4Network:netmask

Return the IPv4 netmask address for this prefix. @param self Current object instance on which the method operates.

IPv4Network:netmask()IPv4Address

Returns

Netmask address for this IPv4 network.

IPv4Network:hostmask

Return the IPv4 hostmask address for this prefix. @param self Current object instance on which the method operates.

IPv4Network:hostmask()IPv4Address

Returns

Hostmask address for this IPv4 network.

IPv4Network:prefixLength

Return the CIDR prefix length for this IPv4 network. @param self Current object instance on which the method operates.

IPv4Network:prefixLength()number

Returns

Numeric result produced by the operation.

IPv4Network:firstHost

Return the first usable host address in this IPv4 network. @param self Current object instance on which the method operates.

IPv4Network:firstHost()IPv4Address

Returns

First usable host address in this network.

IPv4Network:lastHost

Return the last usable host address in this IPv4 network. @param self Current object instance on which the method operates.

IPv4Network:lastHost()IPv4Address

Returns

Last usable host address in this network.

IPv4Network:hostCount

Return the usable host count for this IPv4 network. @param self Current object instance on which the method operates.

IPv4Network:hostCount()number

Returns

Numeric result produced by the operation.

IPv4Network:contains

Return true if an IPv4 address belongs to this network. @param self Current object instance on which the method operates.

IPv4Network:contains(ipAddr: IPv4Address)boolean

Parameters

ipAddr: IPv4Address

IP address value to test against the network.

Returns

result indicating whether the condition is met.

IPv4Network:containsNetwork

Return true if another IPv4 network is fully contained. @param self Current object instance on which the method operates.

IPv4Network:containsNetwork(net: IPv4Network)boolean

Parameters

Network to test membership, overlap, or containment against.

Returns

result indicating whether the condition is met.

IPv4Network:overlaps

Return true if two IPv4 networks overlap. @param self Current object instance on which the method operates.

IPv4Network:overlaps(net: IPv4Network)boolean

Parameters

Network to test membership, overlap, or containment against.

Returns

result indicating whether the condition is met.

IPv4Network:isSubnetOf

Return true if this network is a subnet of another IPv4 network. @param self Current object instance on which the method operates.

IPv4Network:isSubnetOf(net: IPv4Network)boolean

Parameters

Network to test membership, overlap, or containment against.

Returns

result indicating whether the condition is met.

IPv4Network:isSupernetOf

Return true if this network is a supernet of another IPv4 network. @param self Current object instance on which the method operates.

IPv4Network:isSupernetOf(net: IPv4Network)boolean

Parameters

Network to test membership, overlap, or containment against.

Returns

result indicating whether the condition is met.

IPv4Network:subnets

TODO: An __iter, not an array

Iterate child IPv4 subnets at the requested target prefix. @param self Current object instance on which the method operates.

IPv4Network:subnets(newPrefix: number?)(() → IPv4Network?)

Parameters

newPrefix: number?

Target prefix length for subnetting or supernetting.

Returns

(() → IPv4Network?)

-> IPv4Network? Iterator yielding subnet networks at the requested prefix.

IPv4Network:supernet

TODO: An __iter, not an array

Return the containing IPv4 supernet at the requested target prefix. @param self Current object instance on which the method operates.

IPv4Network:supernet(newPrefix: number?)IPv4Network

Parameters

newPrefix: number?

Target prefix length for subnetting or supernetting.

Returns

Containing supernet at the requested prefix.

IPv4Network:toIPv6Mapped

Return the IPv4 network mapped into IPv6 space. @param self Current IPv4Network instance.

IPv4Network:toIPv6Mapped()IPv6Network

Returns

IPv4-mapped IPv6 network with prefix shifted by 96 bits.

IPv4Network:hosts

TODO: An __iter, not an array

Iterate usable IPv4 host addresses in this network lazily. @param self Current object instance on which the method operates.

IPv4Network:hosts()(() → IPv4Address?)

Returns

(() → IPv4Address?)

-> IPv4Address? Iterator yielding usable IPv4 host addresses.

IPv4Network:addresses

TODO: An __iter, not an array

Iterate all IPv4 addresses in this network lazily. @param self Current object instance on which the method operates.

IPv4Network:addresses()(() → IPv4Address?)

Returns

(() → IPv4Address?)

-> IPv4Address? Iterator yielding all IPv4 addresses in range.

IPv6Network

Represents an IPv6 CIDR network.

Properties

version: number

IP version number (6).

_prefix: number

CIDR prefix length.

_network: { number }

Network address as hextets.

IPv6Network.smallestContaining

Return the smallest IPv6 network containing both addresses.

IPv6Network.smallestContaining(a: IPv6Address, b: IPv6Address)IPv6Network

Parameters

First IPv6 address endpoint.

Second IPv6 address endpoint.

Returns

Minimal IPv6 CIDR block that covers both addresses.

IPv6Network.parse

Parse an IPv6 CIDR network string with optional parse options.

IPv6Network.parse(source: string, options: ParseOptions?)IPv6Network?

Parameters

source: string

IPv6 network text to parse.

options: ParseOptions?

Optional parse behavior flags.

Returns

Parsed IPv6Network when the input is valid.

IPv6Network.mergeNetworks

Merge and collapse overlapping/adjacent IPv6 networks.

IPv6Network.mergeNetworks(networks: { IPv6Network | string }){ IPv6Network }

Parameters

networks: { IPv6Network | string }

IPv6Network instances or parseable IPv6 CIDR strings.

Returns

Minimal merged set of IPv6 networks.

IPv6Network:networkAddress

IPv6 Network =====
IPv6Network:networkAddress()IPv6Address

IPv6Network:broadcastAddress

Return the last address in this IPv6 CIDR block. @param self Current object instance on which the method operates.

IPv6Network:broadcastAddress()IPv6Address

Returns

Last address in this IPv6 network range.

IPv6Network:netmask

Return the IPv6 netmask address for this prefix. @param self Current object instance on which the method operates.

IPv6Network:netmask()IPv6Address

Returns

Netmask address for this IPv6 network.

IPv6Network:hostmask

Return the IPv6 hostmask address for this prefix. @param self Current object instance on which the method operates.

IPv6Network:hostmask()IPv6Address

Returns

Hostmask address for this IPv6 network.

IPv6Network:prefixLength

Return the CIDR prefix length for this IPv6 network. @param self Current object instance on which the method operates.

IPv6Network:prefixLength()number

Returns

Numeric result produced by the operation.

IPv6Network:firstHost

Return the first address in this IPv6 network. @param self Current object instance on which the method operates.

IPv6Network:firstHost()IPv6Address

Returns

First address in this IPv6 network.

IPv6Network:lastHost

Return the last address in this IPv6 network. @param self Current object instance on which the method operates.

IPv6Network:lastHost()IPv6Address

Returns

Last address in this IPv6 network.

IPv6Network:hostCount

Return address count for this IPv6 network. @param self Current object instance on which the method operates.

IPv6Network:hostCount()number

Returns

Numeric result produced by the operation.

IPv6Network:contains

Return true if an IPv6 address belongs to this network. @param self Current object instance on which the method operates.

IPv6Network:contains(ipAddr: IPv6Address)boolean

Parameters

ipAddr: IPv6Address

IP address value to test against the network.

Returns

result indicating whether the condition is met.

IPv6Network:containsNetwork

Return true if another IPv6 network is fully contained. @param self Current object instance on which the method operates.

IPv6Network:containsNetwork(net: IPv6Network)boolean

Parameters

Network to test membership, overlap, or containment against.

Returns

result indicating whether the condition is met.

IPv6Network:overlaps

Return true if two IPv6 networks overlap. @param self Current object instance on which the method operates.

IPv6Network:overlaps(net: IPv6Network)boolean

Parameters

Network to test membership, overlap, or containment against.

Returns

result indicating whether the condition is met.

IPv6Network:isSubnetOf

Return true if this network is a subnet of another IPv6 network. @param self Current object instance on which the method operates.

IPv6Network:isSubnetOf(net: IPv6Network)boolean

Parameters

Network to test membership, overlap, or containment against.

Returns

result indicating whether the condition is met.

IPv6Network:isSupernetOf

Return true if this network is a supernet of another IPv6 network. @param self Current object instance on which the method operates.

IPv6Network:isSupernetOf(net: IPv6Network)boolean

Parameters

Network to test membership, overlap, or containment against.

Returns

result indicating whether the condition is met.

IPv6Network:subnets

TODO: An __iter, not an array

Iterate child IPv6 subnets at the requested target prefix. @param self Current object instance on which the method operates.

IPv6Network:subnets(newPrefix: number?)(() → IPv6Network?)

Parameters

newPrefix: number?

Target prefix length for subnetting or supernetting.

Returns

(() → IPv6Network?)

-> IPv6Network? Iterator yielding subnet networks at the requested prefix.

IPv6Network:supernet

TODO: An __iter, not an array

Return the containing IPv6 supernet at the requested target prefix. @param self Current object instance on which the method operates.

IPv6Network:supernet(newPrefix: number?)IPv6Network

Parameters

newPrefix: number?

Target prefix length for subnetting or supernetting.

Returns

Containing supernet at the requested prefix.

IPv6Network:hosts

TODO: An __iter, not an array

Iterate IPv6 host addresses lazily (same sequence as addresses). @param self Current object instance on which the method operates.

IPv6Network:hosts()(() → IPv6Address?)

Returns

(() → IPv6Address?)

-> IPv6Address? Iterator yielding IPv6 host addresses in range.

IPv6Network:addresses

TODO: An __iter, not an array

Iterate IPv6 addresses in this network lazily. @param self Current object instance on which the method operates.

IPv6Network:addresses()(() → IPv6Address?)

Returns

(() → IPv6Address?)

-> IPv6Address? Iterator yielding IPv6 addresses in range.

IPv4Interface

Represents an IPv4 interface assignment (address/prefix).

Properties

address: IPv4Address

Assigned IPv4 address.

network: IPv4Network

Containing IPv4 network.

_prefix: number

Interface prefix length.

IPv4Interface.parse

Parse an IPv4 interface string with optional parse options.

IPv4Interface.parse(source: string, options: ParseOptions?)IPv4Interface?

Parameters

source: string

IPv4 interface text (address/prefix) to parse.

options: ParseOptions?

Optional parse behavior flags.

Returns

Parsed IPv4Interface when the input is valid.

IPv4Interface:prefixLength

Return interface prefix length. @param self Current object instance on which the method operates.

IPv4Interface:prefixLength()number

Returns

Numeric result produced by the operation.

IPv4Interface:netmask

Return interface IPv4 netmask. @param self Current object instance on which the method operates.

IPv4Interface:netmask()IPv4Address

Returns

Netmask for this IPv4 interface.

IPv4Interface:withPrefixLength

eg "192.168.1.10/24"

IPv4Interface:withPrefixLength()string

IPv4Interface:withNetmask

eg "192.168.1.10/255.255.255.0"

IPv4Interface:withNetmask()string

IPv4Interface:hostmask

Return interface IPv4 hostmask. @param self Current object instance on which the method operates.

IPv4Interface:hostmask()IPv4Address

Returns

Hostmask for this IPv4 interface.

IPv6Interface

Represents an IPv6 interface assignment (address/prefix).

Properties

address: IPv6Address

Assigned IPv6 address.

network: IPv6Network

Containing IPv6 network.

_prefix: number

Interface prefix length.

IPv6Interface.parse

Parse an IPv6 interface string with optional parse options.

IPv6Interface.parse(source: string, options: ParseOptions?)IPv6Interface?

Parameters

source: string

IPv6 interface text (address/prefix) to parse.

options: ParseOptions?

Optional parse behavior flags.

Returns

Parsed IPv6Interface when the input is valid.

IPv6Interface:prefixLength

Return interface prefix length. @param self Current object instance on which the method operates.

IPv6Interface:prefixLength()number

Returns

Numeric result produced by the operation.

IPv6Interface:netmask

Return interface IPv6 netmask. @param self Current object instance on which the method operates.

IPv6Interface:netmask()IPv6Address

Returns

Netmask for this IPv6 interface.

IPv6Interface:withPrefixLength

eg "192.168.1.10/26" (but ipv6)

IPv6Interface:withPrefixLength()string

IPv6Interface:withNetmask

eg "192.168.1.10/255.255.255.0" (but ipv6)

IPv6Interface:withNetmask()string

IPv6Interface:hostmask

Return interface IPv6 hostmask. @param self Current object instance on which the method operates.

IPv6Interface:hostmask()IPv6Address

Returns

Hostmask for this IPv6 interface.

IPv4Range

Represents a normalized set of IPv4 segments.

Properties

version: number

IP version number (4).

_segments: { { start: number, finish: number } }

Sorted, non-overlapping inclusive segments.

IPv4Range.new

Build an IPv4 range from start and end addresses (inclusive).

IPv4Range.new(startValue: IPv4Address | string, endValue: IPv4Address | string)IPv4Range

Parameters

startValue: IPv4Address | string

Start address for the range, as IPv4Address or IPv4 string.

endValue: IPv4Address | string

End address for the range, as IPv4Address or IPv4 string.

Returns

IPv4Range covering the inclusive start/end interval.

IPv4Range.fromNetwork

Create an IPv4 range that exactly matches a CIDR network.

IPv4Range.fromNetwork(networkValue: IPv4Network | string)IPv4Range

Parameters

networkValue: IPv4Network | string

IPv4Network instance or parseable IPv4 CIDR string.

Returns

IPv4Range covering every address in the network.

IPv4Range:contains

Check whether an IPv4 range contains the supplied value. @param self Current IPv4Range instance.

IPv4Range:contains(value: IPv4Address | IPv4Network | IPv4Range | string)boolean

Parameters

IPv4Address, IPv4Network, IPv4Range, or parseable string input.

Returns

True when the entire value is contained by this range.

IPv4Range:exclude

Return a new IPv4 range with the supplied address/network/range removed. @param self Current IPv4Range instance.

IPv4Range:exclude(value: IPv4Address | IPv4Network | IPv4Range | string)IPv4Range

Parameters

IPv4Address, IPv4Network, IPv4Range, or parseable string input.

Returns

New IPv4Range after subtraction.

IPv4Range:iter

Lazily iterate all IPv4 addresses in this range. @param self Current IPv4Range instance.

IPv4Range:iter()(() → IPv4Address?)

Returns

(() → IPv4Address?)

-> IPv4Address? Iterator yielding IPv4 addresses in ascending order.

IPv4Range:toNetworks

Lazily enumerate exact covering IPv4 CIDR blocks for this range. @param self Current IPv4Range instance.

IPv4Range:toNetworks()(() → IPv4Network?)

Returns

(() → IPv4Network?)

-> IPv4Network? Iterator yielding minimal IPv4 CIDR blocks.

IPv4Range:smallestContainingNetwork

Return the single smallest IPv4 CIDR that contains this entire range. @param self Current IPv4Range instance.

IPv4Range:smallestContainingNetwork()IPv4Network

Returns

Smallest containing IPv4 network, potentially including extra addresses.

IPv6Range

Represents a normalized set of IPv6 segments.

Properties

version: number

IP version number (6).

_segments: { { start: { number }, finish: { number } } }

Sorted, non-overlapping inclusive segments.

IPv6Range.new

Build an IPv6 range from start and end addresses (inclusive).

IPv6Range.new(startValue: IPv6Address | string, endValue: IPv6Address | string)IPv6Range

Parameters

startValue: IPv6Address | string

Start address for the range, as IPv6Address or IPv6 string.

endValue: IPv6Address | string

End address for the range, as IPv6Address or IPv6 string.

Returns

IPv6Range covering the inclusive start/end interval.

IPv6Range.fromNetwork

Create an IPv6 range that exactly matches a CIDR network.

IPv6Range.fromNetwork(networkValue: IPv6Network | string)IPv6Range

Parameters

networkValue: IPv6Network | string

IPv6Network instance or parseable IPv6 CIDR string.

Returns

IPv6Range covering every address in the network.

IPv6Range:contains

Check whether an IPv6 range contains the supplied value. @param self Current IPv6Range instance.

IPv6Range:contains(value: IPv6Address | IPv6Network | IPv6Range | string)boolean

Parameters

IPv6Address, IPv6Network, IPv6Range, or parseable string input.

Returns

True when the entire value is contained by this range.

IPv6Range:exclude

Return a new IPv6 range with the supplied address/network/range removed. @param self Current IPv6Range instance.

IPv6Range:exclude(value: IPv6Address | IPv6Network | IPv6Range | string)IPv6Range

Parameters

IPv6Address, IPv6Network, IPv6Range, or parseable string input.

Returns

New IPv6Range after subtraction.

IPv6Range:iter

Lazily iterate all IPv6 addresses in this range. @param self Current IPv6Range instance.

IPv6Range:iter()(() → IPv6Address?)

Returns

(() → IPv6Address?)

-> IPv6Address? Iterator yielding IPv6 addresses in ascending order.

IPv6Range:toNetworks

Lazily enumerate exact covering IPv6 CIDR blocks for this range. @param self Current IPv6Range instance.

IPv6Range:toNetworks()(() → IPv6Network?)

Returns

(() → IPv6Network?)

-> IPv6Network? Iterator yielding minimal IPv6 CIDR blocks.

IPv6Range:smallestContainingNetwork

Return the single smallest IPv6 CIDR that contains this entire range. @param self Current IPv6Range instance.

IPv6Range:smallestContainingNetwork()IPv6Network

Returns

Smallest containing IPv6 network, potentially including extra addresses.

Functions

ip.parse

Parse an address or network string into the corresponding IP object.

ip.parse(source: string, options: ParseOptions?)(IPv4Address | IPv6Address | IPv4Network | IPv6Network)?

Parameters

source: string

Source text to parse, validate, or classify.

options: ParseOptions?

Optional parse behavior flags (for example strict).

Returns

Parsed address/network object when the input is valid.

ip.address

Parse a string into an IPv4Address or IPv6Address.

ip.address(source: string, options: ParseOptions?)(IPv4Address | IPv6Address)?

Parameters

source: string

Source text to parse, validate, or classify.

options: ParseOptions?

Optional parse behavior flags (for example allowZoneId).

Returns

Parsed IPv4 or IPv6 address object when valid.

ip.network

Parse a string into an IPv4Network or IPv6Network.

ip.network(source: string, options: ParseOptions?)(IPv4Network | IPv6Network)?

Parameters

source: string

Source text to parse, validate, or classify.

options: ParseOptions?

Optional parse behavior flags (for example strict host-bit checks).

Returns

Parsed IPv4 or IPv6 network object when valid.

ip.interface

Parse a string into an IPv4Interface or IPv6Interface.

ip.interface(source: string, options: ParseOptions?)(IPv4Interface | IPv6Interface)?

Parameters

source: string

Source text to parse, validate, or classify.

options: ParseOptions?

Optional parse behavior flags forwarded to address parsing.

Returns

Parsed IPv4 or IPv6 interface object when valid.

ip.isAddress

Return true when the input is a valid IP address string.

ip.isAddress(source: string)boolean

Parameters

source: string

Source text to parse, validate, or classify.

Returns

True when the input is recognized as a valid address.

ip.isNetwork

Return true when the input is a valid CIDR/network string.

ip.isNetwork(source: string)boolean

Parameters

source: string

Source text to parse, validate, or classify.

Returns

True when the input is recognized as a valid network.

ip.isIPv4

Return true when the input parses as an IPv4 address or network.

ip.isIPv4(source: string)boolean

Parameters

source: string

Source text to parse, validate, or classify.

Returns

True when input resolves to an IPv4 address or network.

ip.isIPv6

Return true when the input parses as an IPv6 address or network.

ip.isIPv6(source: string)boolean

Parameters

source: string

Source text to parse, validate, or classify.

Returns

True when input resolves to an IPv6 address or network.

ip.smallestEnclosingIPv4Network

Return the smallest IPv4 network containing both IPv4 addresses.

ip.smallestEnclosingIPv4Network(a: IPv4Address, b: IPv4Address)IPv4Network

Parameters

Primary input value or left operand.

Secondary input value or right operand.

Returns

Smallest IPv4 CIDR block containing both inputs.

ip.smallestEnclosingIPv6Network

Return the smallest IPv6 network containing both IPv6 addresses.

ip.smallestEnclosingIPv6Network(a: IPv6Address, b: IPv6Address)IPv6Network

Parameters

Primary input value or left operand.

Secondary input value or right operand.

Returns

Smallest IPv6 CIDR block containing both inputs.

ip.sortIPv4

Parse/coerce and sort a list of IPv4 addresses in ascending order.

ip.sortIPv4(values: { IPv4Address | string }){ IPv4Address }

Parameters

values: { IPv4Address | string }

Collection of address values to parse/coerce and sort.

Returns

IPv4 address list sorted in ascending numeric order.

ip.sortIPv6

Parse/coerce and sort a list of IPv6 addresses in ascending order.

ip.sortIPv6(values: { IPv6Address | string }){ IPv6Address }

Parameters

values: { IPv6Address | string }

Collection of address values to parse/coerce and sort.

Returns

IPv6 address list sorted in ascending lexical order.