Represents an IPv4 address.
@eryx/ip Module
JSON
Summary
Classes
Functions
API Reference
Classes
IPv4Address
Properties
IP version number (4).
IPv4 octets in network order.
Packed 32-bit integer representation.
IPv4Address.sort
Sort a collection of IPv4 address values.
Parameters
IPv4Address instances or parseable IPv4 strings.
Returns
Parsed and sorted IPv4 addresses.
IPv4Address.parse
Parse an IPv4 address string with optional parse options.
Parameters
IPv4 address text to parse.
Optional parse behavior flags.
Returns
Parsed IPv4Address when the input is valid.
IPv4Address.fromInteger
Create an IPv4Address from a 32-bit integer.
Parameters
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.
Parameters
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.
Parameters
Buffer or byte array containing exactly four bytes.
Returns
Parsed IPv4Address from packed input.
IPv4Address:toBytes
Pack the four octets into four bytes in a buffer
IPv4Address:toPacked
Return packed IPv4 bytes for this address. @param self Current IPv4Address instance.
Returns
containing four network-order bytes.
IPv4Address:isPrivate
Return true for RFC1918 private IPv4 ranges. @param self Current object instance on which the method operates.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Returns
representation or textual result.
IPv4Address:isBroadcast
Return true for 255.255.255.255. @param self Current object instance on which the method operates.
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.
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.
Returns
Next IPv4 address value.
IPv4Address:previous
Return the previous IPv4 address. @param self Current object instance on which the method operates.
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.
Returns
IPv4-mapped IPv6 equivalent of this address.
IPv6Address
Represents an IPv6 address.
Properties
IP version number (6).
IPv6 hextets in network order.
IPv6Address.sort
Sort a collection of IPv6 address values.
Parameters
IPv6Address instances or parseable IPv6 strings.
Returns
Parsed and sorted IPv6 addresses.
IPv6Address.parse
Parse an IPv6 address string with optional parse options.
Parameters
IPv6 address text to parse.
Optional parse behavior flags.
Returns
Parsed IPv6Address when the input is valid.
IPv6Address.fromBytes
IPv6 Constructors
IPv6Address.fromPacked
Create an IPv6Address from packed byte input.
Parameters
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.
Parameters
Returns
Parsed IPv6Address from integer input.
IPv6Address:toBytes
Pack the bytes into a buffer
IPv6Address:toPacked
Return packed IPv6 bytes for this address. @param self Current IPv6Address instance.
Returns
containing sixteen network-order bytes.
IPv6Address:toInteger
Return the integer representation of this IPv6 address. @param self Current IPv6Address instance.
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.
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.
Returns
result indicating whether the condition is met.
IPv6Address:isLoopback
Return true for ::1. @param self Current object instance on which the method operates.
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.
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.
Returns
result indicating whether the condition is met.
IPv6Address:isUnspecified
Return true for ::. @param self Current object instance on which the method operates.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Returns
"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.
Returns
Embedded IPv4 address when present, otherwise nil.
IPv6Address:toIPv4
Convert mapped/compatible IPv6 addresses back to IPv4. @param self Current IPv6Address instance.
Returns
Extracted IPv4Address when conversion is possible.
IPv6Address:is6to4
Return true for 6to4 IPv6 addresses (2002::/16).
@param self Current IPv6Address instance.
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.
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.
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.
Returns
Next IPv6 address value.
IPv6Address:previous
Return the previous IPv6 address. @param self Current object instance on which the method operates.
Returns
Previous IPv6 address value.
IPv4Network
Represents an IPv4 CIDR network.
Properties
IP version number (4).
CIDR prefix length.
Packed network address as 32-bit integer.
IPv4Network.smallestContaining
Return the smallest IPv4 network containing both addresses.
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.
Parameters
IPv4 network text to parse.
Optional parse behavior flags.
Returns
Parsed IPv4Network when the input is valid.
IPv4Network.mergeNetworks
Merge and collapse overlapping/adjacent IPv4 networks.
Parameters
IPv4Network instances or parseable IPv4 CIDR strings.
Returns
Minimal merged set of IPv4 networks.
IPv4Network:broadcastAddress
Return the broadcast address of this IPv4 CIDR block. @param self Current object instance on which the method operates.
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.
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.
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.
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.
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.
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.
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.
Parameters
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.
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.
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.
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.
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.
Parameters
Target prefix length for subnetting or supernetting.
Returns
-> 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.
Parameters
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.
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.
Returns
-> 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.
Returns
-> IPv4Address? Iterator yielding all IPv4 addresses in range.
IPv6Network
Represents an IPv6 CIDR network.
Properties
IP version number (6).
CIDR prefix length.
Network address as hextets.
IPv6Network.smallestContaining
Return the smallest IPv6 network containing both addresses.
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.
Parameters
IPv6 network text to parse.
Optional parse behavior flags.
Returns
Parsed IPv6Network when the input is valid.
IPv6Network.mergeNetworks
Merge and collapse overlapping/adjacent IPv6 networks.
Parameters
IPv6Network instances or parseable IPv6 CIDR strings.
Returns
Minimal merged set of IPv6 networks.
IPv6Network:broadcastAddress
Return the last address in this IPv6 CIDR block. @param self Current object instance on which the method operates.
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.
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.
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.
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.
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.
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.
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.
Parameters
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.
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.
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.
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.
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.
Parameters
Target prefix length for subnetting or supernetting.
Returns
-> 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.
Parameters
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.
Returns
-> 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.
Returns
-> IPv6Address? Iterator yielding IPv6 addresses in range.
IPv4Interface
Represents an IPv4 interface assignment (address/prefix).
Properties
Assigned IPv4 address.
Containing IPv4 network.
Interface prefix length.
IPv4Interface.parse
Parse an IPv4 interface string with optional parse options.
Parameters
IPv4 interface text (address/prefix) to parse.
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.
Returns
Numeric result produced by the operation.
IPv4Interface:netmask
Return interface IPv4 netmask. @param self Current object instance on which the method operates.
Returns
Netmask for this IPv4 interface.
IPv4Interface:hostmask
Return interface IPv4 hostmask. @param self Current object instance on which the method operates.
Returns
Hostmask for this IPv4 interface.
IPv6Interface
Represents an IPv6 interface assignment (address/prefix).
Properties
Assigned IPv6 address.
Containing IPv6 network.
Interface prefix length.
IPv6Interface.parse
Parse an IPv6 interface string with optional parse options.
Parameters
IPv6 interface text (address/prefix) to parse.
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.
Returns
Numeric result produced by the operation.
IPv6Interface:netmask
Return interface IPv6 netmask. @param self Current object instance on which the method operates.
Returns
Netmask for this IPv6 interface.
IPv6Interface:withPrefixLength
eg "192.168.1.10/26" (but ipv6)
IPv6Interface:withNetmask
eg "192.168.1.10/255.255.255.0" (but ipv6)
IPv6Interface:hostmask
Return interface IPv6 hostmask. @param self Current object instance on which the method operates.
Returns
Hostmask for this IPv6 interface.
IPv4Range
Represents a normalized set of IPv4 segments.
Properties
IP version number (4).
IPv4Range.new
Build an IPv4 range from start and end addresses (inclusive).
Parameters
Start address for the range, as IPv4Address or IPv4 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.
Parameters
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.
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.
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.
Returns
-> 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.
Returns
-> 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.
Returns
Smallest containing IPv4 network, potentially including extra addresses.
IPv6Range
Represents a normalized set of IPv6 segments.
Properties
IP version number (6).
Sorted, non-overlapping inclusive segments.
IPv6Range.new
Build an IPv6 range from start and end addresses (inclusive).
Parameters
Start address for the range, as IPv6Address or IPv6 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.
Parameters
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.
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.
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.
Returns
-> 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.
Returns
-> 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.
Returns
Smallest containing IPv6 network, potentially including extra addresses.
Functions
ip.parse
Parse an address or network string into the corresponding IP object.
Parameters
Source text to parse, validate, or classify.
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.
Parameters
Source text to parse, validate, or classify.
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.
Parameters
Source text to parse, validate, or classify.
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.
Parameters
Source text to parse, validate, or classify.
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.
Parameters
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.
Parameters
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.
Parameters
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.
Parameters
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.
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.
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.
Parameters
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.
Parameters
Collection of address values to parse/coerce and sort.
Returns
IPv6 address list sorted in ascending lexical order.