cidrAddresses(cidr: Cidrv4,options?: { offset?: number; count?: number; step?: number; }): Generator<number>
cidrAddresses(cidr: Cidrv6,options?: { offset?: number | bigint; count?: number | bigint; step?: number | bigint; }): Generator<bigint>
cidrAddresses(cidr: Cidr,options?: { offset?: number | bigint; count?: number | bigint; step?: number | bigint; }): Generator<Address>
Generates IP addresses within a CIDR block.
Dispatches to cidrv4Addresses or cidrv6Addresses based on the address type. Yields addresses lazily for memory-efficient iteration.
Example 1
Example 1
import { assertEquals } from "@std/assert"; import { cidrAddresses, parseCidr } from "@hertzg/ip/cidr"; import { stringifyAddress } from "@hertzg/ip/address"; const first3 = Array.from(cidrAddresses(parseCidr("10.0.0.0/29"), { count: 3 })); assertEquals(first3.map(stringifyAddress), [ "10.0.0.0", "10.0.0.1", "10.0.0.2", ]);
cidr: Cidr
The CIDR block to enumerate
Generator<Address>
A generator yielding addresses (number for IPv4, bigint for IPv6)