Sign in

    ipset

    Pure MoonBit IPv4/IPv6 addresses, networks, interfaces and address sets

    ipaddress
    ipv4
    ipv6
    cidr
    subnet
    network
    interface
    set
    Download zip
    Version
    0.3.0
    License
    MIT
    Last updated
    2 hours ago
    Downloads
    17

    No dependencies

    #moon-ipset

    纯 MoonBit 通用 IPv4/IPv6 地址、网络、接口与集合库。以 CPython 3.13.2 ipaddress 为行为参考,支持 wasm、wasm-gc、JavaScript 和 native;核心只依赖 MoonBit 标准库。

    #功能

    • 地址 IpAddress:文本、字节、大整数转换,压缩/展开格式、PTR、scope ID、地址属性、mapped IPv6、6to4、Teredo、比较与受检算术。
    • 网络 IpNetwork:CIDR、IPv4 掩码/反掩码、严格校验、子网/超网、主机遍历、包含与重叠、排除、范围汇总和网段归并。
    • 接口 IpInterface:同时保留主机地址与网络前缀,提供地址、网络、掩码和转换方法。这里的接口是配置值,不是操作系统网卡。
    • 集合 IpSet:并、交、差、对称差、成员与子集判断,以及最小 CIDR 覆盖;旧版 Address、Cidr 和 CLI 保持兼容。

    地址数量使用 BigInt,包括 IPv6 /0 的 2^128 个地址;hosts()、iter() 和 subnets() 惰性生成,使用 take(n) 可限制输出。

    #安装与使用

    moon add tc-adventureking/ipset@0.3.0

    在 moon.pkg 中导入:

    import { "tc-adventureking/ipset" @ip, }

    test "interface and subnet" {
    let iface = @ip.ip_interface("192.168.10.7/24")
    assert_eq(iface.ip().to_string(), "192.168.10.7")
    assert_eq(iface.network().to_string(), "192.168.10.0/24")
    let first = iface.network().subnets(new_prefix=26).next().unwrap()
    assert_eq(first.hosts().next().unwrap().to_string(), "192.168.10.1")
    assert_false(@ip.ip_address("100.64.0.1").is_global())
    }

    ip_network 默认严格拒绝非零主机位;需要归一化时传 strict=false。接口加减会返回 /32 或 /128 的新接口。地址属性依据固定参考版本,is_private 不只表示 RFC1918 私有地址。

    #示例与测试

    安装 MoonBit 工具链后在仓库运行:

    moon -C examples/consumer run . --target wasm-gc moon test --deny-warn --target all

    独立消费示例涵盖地址清单校验、子网规划、双栈接口配置和集合排除。完整公开检查运行 bash scripts/verify.sh,需要 Node.js 24 LTS 和 C 工具链,无需 Python。验证范围。

    #网段文件 CLI

    每行一个 IP/CIDR,支持空行、# 注释和标准输入 -:

    node bin/ipset.mjs normalize examples/policies/new.txt node bin/ipset.mjs diff examples/policies/old.txt examples/policies/new.txt --json

    退出码:0 成功或无变化,1 diff 有变化,2 输入或运行错误。该 CLI 比较地址集合,不解释防火墙规则顺序。文件与 JSONL 协议。

    #许可

    项目代码使用 MIT;CPython 参考部分保留 Python 许可,MoonBit 标准库保留其自身许可。来源与修改说明见 PROVENANCE。

    IpError

    pub(all) suberror IpError {
    InvalidAddress(String)
    InvalidPrefix(String)
    InvalidRange(String)
    HostBitsSet(String)
    } derive(Eq)

    Invalid input is reported without constructing an invalid address or range.
    impl Show for IpError

    IpError::equal

    fn IpError::equal(IpError, IpError) -> Bool

    IpError::not_equal

    fn IpError::not_equal(x : IpError, y : IpError) -> Bool

    IpError::output

    fn IpError::output(self : IpError, logger : &Logger) -> Unit

    IpError::to_string

    fn IpError::to_string(self : IpError) -> String

    Address

    type Address derive(Eq)

    An immutable address. The four words are in network (most significant first) order.
    impl Compare for Address
    impl Show for Address

    Address::compare

    fn Address::compare(self : Address, other : Address) -> Int

    Address::equal

    fn Address::equal(Address, Address) -> Bool

    Address::family

    fn Address::family(self : Address) -> Family

    Returns the address family, without interpreting mapped addresses as IPv4.

    Address::next

    fn Address::next(self : Address) -> Address?

    Returns the next address in the same family, or None at its maximum value.

    Address::not_equal

    fn Address::not_equal(x : Address, y : Address) -> Bool

    Address::op_ge

    fn Address::op_ge(x : Address, y : Address) -> Bool

    Address::op_gt

    fn Address::op_gt(x : Address, y : Address) -> Bool

    Address::op_le

    fn Address::op_le(x : Address, y : Address) -> Bool

    Address::op_lt

    fn Address::op_lt(x : Address, y : Address) -> Bool

    Address::output

    fn Address::output(self : Address, logger : &Logger) -> Unit

    Address::parse

    fn Address::parse(text : String) -> Address raise IpError

    Parses strict IPv4 or IPv6 text; rejects whitespace, zones, brackets, and ports.

    Address::previous

    fn Address::previous(self : Address) -> Address?

    Returns the preceding address in the same family, or None at zero.

    Address::to_string

    fn Address::to_string(self : Address) -> String

    Formats IPv4 dotted decimal or lowercase compressed IPv6 (including mapped addresses).

    Address::width

    fn Address::width(self : Address) -> Int

    Returns the width of this address family in bits.

    Cidr

    type Cidr derive(Eq)

    A canonical CIDR network; host bits are zero and the prefix fits the family.
    impl Show for Cidr

    Cidr::equal

    fn Cidr::equal(Cidr, Cidr) -> Bool

    Cidr::last

    fn Cidr::last(self : Cidr) -> Address

    The inclusive final address of this network.

    Cidr::network

    fn Cidr::network(self : Cidr) -> Address

    The first address of this network.

    Cidr::new

    fn Cidr::new(address : Address, prefix : Int, strict? : Bool) -> Cidr raise IpError

    Constructs a CIDR, clearing host bits unless strict validation is requested.

    Cidr::not_equal

    fn Cidr::not_equal(x : Cidr, y : Cidr) -> Bool

    Cidr::output

    fn Cidr::output(self : Cidr, logger : &Logger) -> Unit

    Cidr::parse

    fn Cidr::parse(text : String, strict? : Bool) -> Cidr raise IpError

    Parses address/prefix syntax. The prefix uses decimal digits without leading zeros.

    Cidr::prefix

    fn Cidr::prefix(self : Cidr) -> Int

    Number of leading network bits.

    Cidr::to_string

    fn Cidr::to_string(self : Cidr) -> String

    Canonical network address followed by a decimal prefix.

    Family

    pub(all) enum Family {
    V4
    V6
    } derive(Compare, Eq)

    Address families are distinct, including IPv4-mapped IPv6 addresses.
    impl Show for Family

    Family::compare

    fn Family::compare(Family, Family) -> Int

    Family::equal

    fn Family::equal(Family, Family) -> Bool

    Family::not_equal

    fn Family::not_equal(x : Family, y : Family) -> Bool

    Family::op_ge

    fn Family::op_ge(x : Family, y : Family) -> Bool

    Family::op_gt

    fn Family::op_gt(x : Family, y : Family) -> Bool

    Family::op_le

    fn Family::op_le(x : Family, y : Family) -> Bool

    Family::op_lt

    fn Family::op_lt(x : Family, y : Family) -> Bool

    Family::output

    fn Family::output(self : Family, logger : &Logger) -> Unit

    Family::to_string

    fn Family::to_string(self : Family) -> String

    Interval

    pub struct Interval {
    // private fields
    } derive(Eq)

    An inclusive interval in exactly one IP address family. Construct with Interval::new; endpoints cannot be changed afterwards.

    Interval::equal

    fn Interval::equal(Interval, Interval) -> Bool

    Interval::first

    fn Interval::first(self : Interval) -> Address

    Return the first address, including that address in the range.

    Interval::last

    fn Interval::last(self : Interval) -> Address

    Return the last address, including that address in the range.

    Interval::new

    fn Interval::new(first : Address, last : Address) -> Interval raise IpError

    Validate and create an inclusive address interval.

    Interval::not_equal

    fn Interval::not_equal(x : Interval, y : Interval) -> Bool

    IpAddress

    type IpAddress derive(Eq)

    A general IP address with an optional IPv6 zone identifier. Legacy Address remains an unscoped numeric address for set algebra.
    impl Hash for IpAddress
    impl Show for IpAddress

    IpAddress::add

    IpAddress::as_address

    fn IpAddress::as_address(self : IpAddress) -> Address

    IpAddress::compare

    fn IpAddress::compare(self : IpAddress, other : IpAddress) -> Int

    IpAddress::compressed

    fn IpAddress::compressed(self : IpAddress) -> String

    IpAddress::equal

    fn IpAddress::equal(IpAddress, IpAddress) -> Bool

    IpAddress::exploded

    fn IpAddress::exploded(self : IpAddress) -> String

    IpAddress::family

    fn IpAddress::family(self : IpAddress) -> Family

    IpAddress::format

    fn IpAddress::format(self : IpAddress, spec : String) -> String raise IpError

    String formatting uses [[fill]align][0][width][.precision]s, with <, > or ^ alignment, one Unicode fill character and ASCII decimal width/precision up to 2147483647. Width and precision count Unicode characters. Numeric b/x/X/n formatting supports optional # prefix and _ grouping.

    IpAddress::from_address

    fn IpAddress::from_address(address : Address) -> IpAddress

    IpAddress::from_bigint

    fn IpAddress::from_bigint(value :
    BigInt
    , family? : Family) -> IpAddress raise IpError

    IpAddress::from_bytes

    fn IpAddress::from_bytes(value : Bytes) -> IpAddress raise IpError

    IpAddress::hash

    fn IpAddress::hash(self : IpAddress) -> Int

    IpAddress::hash_combine

    fn IpAddress::hash_combine(self : IpAddress, hasher : Hasher) -> Unit

    IpAddress::ipv4_mapped

    fn IpAddress::ipv4_mapped(self : IpAddress) -> IpAddress?

    IpAddress::ipv6_mapped

    fn IpAddress::ipv6_mapped(self : IpAddress) -> IpAddress?

    IpAddress::is_global

    fn IpAddress::is_global(self : IpAddress) -> Bool

    fn IpAddress::is_link_local(self : IpAddress) -> Bool

    IpAddress::is_loopback

    fn IpAddress::is_loopback(self : IpAddress) -> Bool

    IpAddress::is_multicast

    fn IpAddress::is_multicast(self : IpAddress) -> Bool

    IpAddress::is_private

    fn IpAddress::is_private(self : IpAddress) -> Bool

    IpAddress::is_reserved

    fn IpAddress::is_reserved(self : IpAddress) -> Bool

    IpAddress::is_site_local

    fn IpAddress::is_site_local(self : IpAddress) -> Bool

    IpAddress::is_unspecified

    fn IpAddress::is_unspecified(self : IpAddress) -> Bool

    IpAddress::max_prefixlen

    fn IpAddress::max_prefixlen(self : IpAddress) -> Int

    IpAddress::not_equal

    fn IpAddress::not_equal(x : IpAddress, y : IpAddress) -> Bool

    IpAddress::op_ge

    fn IpAddress::op_ge(x : IpAddress, y : IpAddress) -> Bool

    IpAddress::op_gt

    fn IpAddress::op_gt(x : IpAddress, y : IpAddress) -> Bool

    IpAddress::op_le

    fn IpAddress::op_le(x : IpAddress, y : IpAddress) -> Bool

    IpAddress::op_lt

    fn IpAddress::op_lt(x : IpAddress, y : IpAddress) -> Bool

    IpAddress::output

    fn IpAddress::output(self : IpAddress, logger : &Logger) -> Unit

    IpAddress::parse

    fn IpAddress::parse(text : String) -> IpAddress raise IpError

    IpAddress::reverse_pointer

    fn IpAddress::reverse_pointer(self : IpAddress) -> String

    The numeric PTR name. IPv6 zone identifiers do not enter DNS names.

    IpAddress::scope_id

    fn IpAddress::scope_id(self : IpAddress) -> String?

    IpAddress::sixtofour

    fn IpAddress::sixtofour(self : IpAddress) -> IpAddress?

    IpAddress::subtract

    IpAddress::teredo

    fn IpAddress::teredo(self : IpAddress) -> (IpAddress, IpAddress)?

    IpAddress::to_bigint

    IpAddress::to_bytes

    fn IpAddress::to_bytes(self : IpAddress) -> Bytes

    IpAddress::to_repr

    IpAddress::to_string

    fn IpAddress::to_string(self : IpAddress) -> String

    IpAddress::unscoped

    fn IpAddress::unscoped(self : IpAddress) -> IpAddress

    IpAddress::version

    fn IpAddress::version(self : IpAddress) -> Int

    IpInput

    pub(all) enum IpInput {
    AddressInput(IpAddress)
    InterfaceInput(IpInterface)
    NetworkInput(IpNetwork)
    } derive(Eq)

    Explicitly distinguish host addresses, interfaces and networks for mixed operations. An interface contributes its host address, not its subnet.
    impl Show for IpInput

    IpInput::equal

    fn IpInput::equal(IpInput, IpInput) -> Bool

    IpInput::not_equal

    fn IpInput::not_equal(x : IpInput, y : IpInput) -> Bool

    IpInput::output

    fn IpInput::output(self : IpInput, logger : &Logger) -> Unit

    IpInput::to_string

    fn IpInput::to_string(self : IpInput) -> String

    IpInterface

    type IpInterface derive(Eq)

    An IP host address paired with a network prefix. Unlike IpNetwork, this type preserves host bits. It models a value, not an OS network adapter.
    impl Hash for IpInterface
    impl Show for IpInterface

    IpInterface::add

    IpInterface::address

    fn IpInterface::address(self : IpInterface) -> IpAddress

    The original host address including an optional IPv6 scope identifier.

    IpInterface::compare

    fn IpInterface::compare(self : IpInterface, other : IpInterface) -> Int

    IpInterface::compressed

    fn IpInterface::compressed(self : IpInterface) -> String

    IpInterface::equal

    fn IpInterface::equal(IpInterface, IpInterface) -> Bool

    IpInterface::exploded

    fn IpInterface::exploded(self : IpInterface) -> String

    Retains /prefix even for IPv4-mapped IPv6 (Python 3.13.2 drops it).

    IpInterface::family

    fn IpInterface::family(self : IpInterface) -> Family

    IpInterface::format

    fn IpInterface::format(self : IpInterface, spec : String) -> String raise IpError

    IpInterface::from_address

    fn IpInterface::from_address(address : IpAddress, prefix : Int) -> IpInterface raise IpError

    IpInterface::from_bigint

    fn IpInterface::from_bigint(value :
    BigInt
    , prefix? : Int, family? : Family) -> IpInterface raise IpError

    IpInterface::from_bytes

    fn IpInterface::from_bytes(bytes : Bytes, prefix? : Int) -> IpInterface raise IpError

    IpInterface::hash

    fn IpInterface::hash(self : IpInterface) -> Int

    IpInterface::hash_combine

    fn IpInterface::hash_combine(self : IpInterface, hasher : Hasher) -> Unit

    IpInterface::hostmask

    fn IpInterface::hostmask(self : IpInterface) -> IpAddress

    IpInterface::ip

    Numeric host address with no scope identifier, like Python's .ip property.

    IpInterface::ipv4_mapped

    fn IpInterface::ipv4_mapped(self : IpInterface) -> IpAddress?

    IpInterface::ipv6_mapped

    fn IpInterface::ipv6_mapped(self : IpInterface) -> IpAddress?

    IpInterface::is_global

    fn IpInterface::is_global(self : IpInterface) -> Bool

    fn IpInterface::is_link_local(self : IpInterface) -> Bool

    IpInterface::is_loopback

    fn IpInterface::is_loopback(self : IpInterface) -> Bool

    IpInterface::is_multicast

    fn IpInterface::is_multicast(self : IpInterface) -> Bool

    IpInterface::is_private

    fn IpInterface::is_private(self : IpInterface) -> Bool

    IpInterface::is_reserved

    fn IpInterface::is_reserved(self : IpInterface) -> Bool

    IpInterface::is_site_local

    fn IpInterface::is_site_local(self : IpInterface) -> Bool

    IpInterface::is_unspecified

    fn IpInterface::is_unspecified(self : IpInterface) -> Bool

    Python 3.13.2 treats IPv4 interfaces as distinct from the bare unspecified address, so this is false for IPv4; use ip().is_unspecified() for host-only classification. IPv6 requires both the host and network to be unspecified.

    IpInterface::max_prefixlen

    fn IpInterface::max_prefixlen(self : IpInterface) -> Int

    IpInterface::netmask

    fn IpInterface::netmask(self : IpInterface) -> IpAddress

    IpInterface::network

    fn IpInterface::network(self : IpInterface) -> IpNetwork

    IpInterface::not_equal

    fn IpInterface::not_equal(x : IpInterface, y : IpInterface) -> Bool

    IpInterface::op_ge

    fn IpInterface::op_ge(x : IpInterface, y : IpInterface) -> Bool

    IpInterface::op_gt

    fn IpInterface::op_gt(x : IpInterface, y : IpInterface) -> Bool

    IpInterface::op_le

    fn IpInterface::op_le(x : IpInterface, y : IpInterface) -> Bool

    IpInterface::op_lt

    fn IpInterface::op_lt(x : IpInterface, y : IpInterface) -> Bool

    IpInterface::output

    fn IpInterface::output(self : IpInterface, logger : &Logger) -> Unit

    IpInterface::parse

    fn IpInterface::parse(text : String) -> IpInterface raise IpError

    IpInterface::prefixlen

    fn IpInterface::prefixlen(self : IpInterface) -> Int

    IpInterface::reverse_pointer

    fn IpInterface::reverse_pointer(self : IpInterface) -> String

    Reverse-DNS name of the host address, without interface prefix or scope.

    IpInterface::scope_id

    fn IpInterface::scope_id(self : IpInterface) -> String?

    IpInterface::sixtofour

    fn IpInterface::sixtofour(self : IpInterface) -> IpAddress?

    IpInterface::subtract

    IpInterface::teredo

    fn IpInterface::teredo(self : IpInterface) -> (IpAddress, IpAddress)?

    IpInterface::to_bigint

    IpInterface::to_bytes

    fn IpInterface::to_bytes(self : IpInterface) -> Bytes

    IpInterface::to_repr

    IpInterface::to_string

    fn IpInterface::to_string(self : IpInterface) -> String

    IpInterface::version

    fn IpInterface::version(self : IpInterface) -> Int

    IpInterface::with_hostmask

    fn IpInterface::with_hostmask(self : IpInterface) -> String

    IpInterface::with_netmask

    fn IpInterface::with_netmask(self : IpInterface) -> String

    IpInterface::with_prefixlen

    fn IpInterface::with_prefixlen(self : IpInterface) -> String

    Explicit prefix/mask variants omit the scope, matching Python's interface properties; to_string()/compressed() retain it.

    IpNetwork

    type IpNetwork derive(Eq)

    A dual-stack IP network. Scoped IPv6 network addresses retain their scope only when construction does not need to clear host bits, matching Python.
    impl Hash for IpNetwork
    impl Show for IpNetwork

    IpNetwork::address_exclude

    fn IpNetwork::address_exclude(self : IpNetwork, other : IpNetwork) -> Iter[IpNetwork] raise IpError

    Remove a contained network in at most 128 lazy binary partition steps. Results use Python's sibling-first order rather than numeric sorting. Containment uses numeric ranges and output networks do not retain scope.

    IpNetwork::as_cidr

    fn IpNetwork::as_cidr(self : IpNetwork) -> Cidr

    IpNetwork::broadcast_address

    fn IpNetwork::broadcast_address(self : IpNetwork) -> IpAddress

    Inclusive final address; IPv6 uses this name for parity with ipaddress.

    IpNetwork::compare

    fn IpNetwork::compare(self : IpNetwork, other : IpNetwork) -> Int

    IpNetwork::compare_networks

    fn IpNetwork::compare_networks(self : IpNetwork, other : IpNetwork) -> Int raise IpError

    Compare numeric network addresses, then prefixes; return -1, 0 or 1. Different families raise InvalidRange. Scope is intentionally ignored: unlike Compare, distinct scoped objects can compare equal here. This avoids Python 3.13.2 returning 1 in both directions for equal bases with new scopes.

    IpNetwork::compressed

    fn IpNetwork::compressed(self : IpNetwork) -> String

    IpNetwork::contains

    fn IpNetwork::contains(self : IpNetwork, address : IpAddress) -> Bool

    IpNetwork::equal

    fn IpNetwork::equal(IpNetwork, IpNetwork) -> Bool

    IpNetwork::exploded

    fn IpNetwork::exploded(self : IpNetwork) -> String

    Expanded IPv6 representation. Scope is retained (Python's scoped exploded formatter raises instead); this method remains total for valid values.

    IpNetwork::family

    fn IpNetwork::family(self : IpNetwork) -> Family

    IpNetwork::from_address

    fn IpNetwork::from_address(address : IpAddress, prefix : Int, strict? : Bool) -> IpNetwork raise IpError

    IpNetwork::from_address_mask

    fn IpNetwork::from_address_mask(address : IpAddress, mask : String, strict? : Bool) -> IpNetwork raise IpError

    Construct from a typed address and decimal prefix, IPv4 netmask or hostmask. IPv6 accepts a decimal prefix only. Strict defaults true, as with parse.

    IpNetwork::from_bigint

    fn IpNetwork::from_bigint(value :
    BigInt
    , prefix? : Int, family? : Family, strict? : Bool) -> IpNetwork raise IpError

    IpNetwork::from_bytes

    fn IpNetwork::from_bytes(bytes : Bytes, prefix? : Int, strict? : Bool) -> IpNetwork raise IpError

    IpNetwork::from_cidr

    fn IpNetwork::from_cidr(cidr : Cidr) -> IpNetwork

    IpNetwork::hash

    fn IpNetwork::hash(self : IpNetwork) -> Int

    IpNetwork::hash_combine

    fn IpNetwork::hash_combine(self : IpNetwork, hasher : Hasher) -> Unit

    IpNetwork::hostmask

    fn IpNetwork::hostmask(self : IpNetwork) -> IpAddress

    IpNetwork::hosts

    fn IpNetwork::hosts(self : IpNetwork) -> Iter[IpAddress]

    IPv4 excludes network/broadcast except /31 and /32; IPv6 excludes subnet router anycast except /127 and /128. Iteration uses constant auxiliary space.

    IpNetwork::is_global

    fn IpNetwork::is_global(self : IpNetwork) -> Bool

    fn IpNetwork::is_link_local(self : IpNetwork) -> Bool

    IpNetwork::is_loopback

    fn IpNetwork::is_loopback(self : IpNetwork) -> Bool

    IpNetwork::is_multicast

    fn IpNetwork::is_multicast(self : IpNetwork) -> Bool

    IpNetwork::is_private

    fn IpNetwork::is_private(self : IpNetwork) -> Bool

    IpNetwork::is_reserved

    fn IpNetwork::is_reserved(self : IpNetwork) -> Bool

    IpNetwork::is_site_local

    fn IpNetwork::is_site_local(self : IpNetwork) -> Bool

    IpNetwork::is_unspecified

    fn IpNetwork::is_unspecified(self : IpNetwork) -> Bool

    IpNetwork::iter

    fn IpNetwork::iter(self : IpNetwork) -> Iter[IpAddress]

    Lazily iterate all numeric addresses, without allocating the address space.

    IpNetwork::max_prefixlen

    fn IpNetwork::max_prefixlen(self : IpNetwork) -> Int

    IpNetwork::netmask

    fn IpNetwork::netmask(self : IpNetwork) -> IpAddress

    IpNetwork::network_address

    fn IpNetwork::network_address(self : IpNetwork) -> IpAddress

    IpNetwork::not_equal

    fn IpNetwork::not_equal(x : IpNetwork, y : IpNetwork) -> Bool

    IpNetwork::nth

    Zero-based address indexing; negative indices count back from the end.

    IpNetwork::num_addresses

    Exact cardinality, including the 2^128 addresses of IPv6 /0.

    IpNetwork::op_ge

    fn IpNetwork::op_ge(x : IpNetwork, y : IpNetwork) -> Bool

    IpNetwork::op_gt

    fn IpNetwork::op_gt(x : IpNetwork, y : IpNetwork) -> Bool

    IpNetwork::op_le

    fn IpNetwork::op_le(x : IpNetwork, y : IpNetwork) -> Bool

    IpNetwork::op_lt

    fn IpNetwork::op_lt(x : IpNetwork, y : IpNetwork) -> Bool

    IpNetwork::output

    fn IpNetwork::output(self : IpNetwork, logger : &Logger) -> Unit

    IpNetwork::overlaps

    fn IpNetwork::overlaps(self : IpNetwork, other : IpNetwork) -> Bool

    IpNetwork::parse

    fn IpNetwork::parse(text : String, strict? : Bool) -> IpNetwork raise IpError

    Parse an IPv4/IPv6 network; unlike legacy Cidr::parse, strict defaults true.

    IpNetwork::prefixlen

    fn IpNetwork::prefixlen(self : IpNetwork) -> Int

    IpNetwork::subnet_of

    fn IpNetwork::subnet_of(self : IpNetwork, other : IpNetwork) -> Bool raise IpError

    Numeric containment ignores IPv6 scope, including equal network bases. This differs from Python's scope-sensitive endpoint equality checks.

    IpNetwork::subnets

    fn IpNetwork::subnets(self : IpNetwork, prefixlen_diff? : Int, new_prefix? : Int) -> Iter[IpNetwork] raise IpError

    Lazily split into equal-size subnets. Only one resulting block is retained.

    IpNetwork::supernet

    fn IpNetwork::supernet(self : IpNetwork, prefixlen_diff? : Int, new_prefix? : Int) -> IpNetwork raise IpError

    IpNetwork::supernet_of

    fn IpNetwork::supernet_of(self : IpNetwork, other : IpNetwork) -> Bool raise IpError

    IpNetwork::to_repr

    IpNetwork::to_string

    fn IpNetwork::to_string(self : IpNetwork) -> String

    IpNetwork::version

    fn IpNetwork::version(self : IpNetwork) -> Int

    IpNetwork::with_hostmask

    fn IpNetwork::with_hostmask(self : IpNetwork) -> String

    IpNetwork::with_netmask

    fn IpNetwork::with_netmask(self : IpNetwork) -> String

    IpNetwork::with_prefixlen

    fn IpNetwork::with_prefixlen(self : IpNetwork) -> String

    IpSet

    pub struct IpSet {
    // private fields
    } derive(Eq)

    An immutable set of IPv4 and/or IPv6 addresses. Intervals are sorted, non-overlapping, and non-adjacent within each family. IPv4 and IPv6 (including IPv4-mapped IPv6 addresses) remain distinct.

    IpSet::cidrs

    fn IpSet::cidrs(self : IpSet) -> Array[Cidr]

    Return the sorted minimal CIDR cover of this set, without enumerating hosts. At each cursor take the largest aligned block contained in its interval. A /0 is emitted directly for a full address family.

    IpSet::contains

    fn IpSet::contains(self : IpSet, address : Address) -> Bool

    Test membership with binary search over normalized intervals.

    IpSet::difference

    fn IpSet::difference(self : IpSet, other : IpSet) -> IpSet

    Return addresses in this set but not in other. Closed intervals avoid an unrepresentable 2^128 upper endpoint. Optional successor/predecessor values handle the two domain limits explicitly.

    IpSet::empty

    fn IpSet::empty() -> IpSet

    Create a set with no addresses.

    IpSet::equal

    fn IpSet::equal(IpSet, IpSet) -> Bool

    IpSet::from_cidrs

    fn IpSet::from_cidrs(cidrs : Array[String]) -> IpSet raise IpError

    Parse and combine CIDR networks, normalizing any host bits in the input. One invalid CIDR rejects the entire construction.

    IpSet::from_ranges

    fn IpSet::from_ranges(ranges : Array[Interval]) -> IpSet

    Canonicalize a collection of valid intervals. The caller's array is copied before sorting; subsequent mutations of it cannot change this set.

    IpSet::intersection

    fn IpSet::intersection(self : IpSet, other : IpSet) -> IpSet

    Return addresses present in both operands, in O(m+n) interval comparisons.

    IpSet::intervals

    fn IpSet::intervals(self : IpSet) -> Array[Interval]

    Return a copy of the canonical intervals. Modifying the returned array does not mutate this set.

    IpSet::is_empty

    fn IpSet::is_empty(self : IpSet) -> Bool

    Whether the set contains no addresses.

    IpSet::is_subset_of

    fn IpSet::is_subset_of(self : IpSet, other : IpSet) -> Bool

    Whether every address in this set also belongs to other. Scans canonical intervals in O(m+n) time and O(1) extra space, returning immediately when an interval is not covered. A continuous source interval must fit in one canonical covering interval because distinct ones have gaps.

    IpSet::not_equal

    fn IpSet::not_equal(x : IpSet, y : IpSet) -> Bool

    IpSet::overlaps

    fn IpSet::overlaps(self : IpSet, other : IpSet) -> Bool

    Whether the operands share at least one address.

    IpSet::symmetric_difference

    fn IpSet::symmetric_difference(self : IpSet, other : IpSet) -> IpSet

    Return addresses present in exactly one operand.

    IpSet::union

    fn IpSet::union(self : IpSet, other : IpSet) -> IpSet

    Return all addresses present in either operand. Neither operand is mutated. Runs in O(m+n) for m and n canonical intervals.

    collapse_addresses

    fn collapse_addresses(networks : Array[IpNetwork]) -> Array[IpNetwork] raise IpError

    Merge overlapping/adjacent networks of one address family. Scopes are not address bits and are omitted from the resulting canonical numeric cover.

    collapse_ip_inputs

    fn collapse_ip_inputs(inputs : Array[IpInput]) -> Array[IpNetwork] raise IpError

    Minimal CIDR cover of hosts, interfaces and networks from one family. Hosts and interface hosts become /32 or /128 networks, ignoring interface prefixes. Like collapse_addresses, the output is a canonical numeric cover: IPv6 zones are discarded, never used to merge address bits.

    get_mixed_type_key

    fn get_mixed_type_key(input : IpInput) -> (Int,
    BigInt
    , Int)

    Numeric mixed sort key: version, address value, then -1 for a host or the network prefix length. Hosts precede networks with the same base address; broader networks precede narrower ones with that same base. For unscoped addresses and networks this reproduces Python's ordering. Zone identifiers are not part of this numeric key; equal keys do not imply identical scoped objects. Interfaces use their host value and ignore the prefix. Python's comparison between two Interface objects can instead compare their networks first.

    ip_address

    fn ip_address(text : String) -> IpAddress raise IpError

    ip_interface

    fn ip_interface(text : String) -> IpInterface raise IpError

    ip_network

    fn ip_network(text : String, strict? : Bool) -> IpNetwork raise IpError

    ipv4_address

    fn ipv4_address(text : String) -> IpAddress raise IpError

    ipv4_interface

    fn ipv4_interface(text : String) -> IpInterface raise IpError

    ipv4_network

    fn ipv4_network(text : String, strict? : Bool) -> IpNetwork raise IpError

    ipv6_address

    fn ipv6_address(text : String) -> IpAddress raise IpError

    ipv6_interface

    fn ipv6_interface(text : String) -> IpInterface raise IpError

    ipv6_network

    fn ipv6_network(text : String, strict? : Bool) -> IpNetwork raise IpError

    summarize_address_range

    fn summarize_address_range(first : IpAddress, last : IpAddress) -> Array[IpNetwork] raise IpError

    Exact minimal CIDR cover of an inclusive numeric range, in ascending order. Ignore IPv6 scope on both endpoints and omit it from the resulting cover.

    v4_int_to_packed

    fn v4_int_to_packed(value :
    BigInt
    ) -> Bytes raise IpError

    v6_int_to_packed

    fn v6_int_to_packed(value :
    BigInt
    ) -> Bytes raise IpError