I knew what a CIDR block was but hadn't thought about it in terms of raw bit ops in a while.
First, parse the CIDR string to extract the IP address and prefix length. Then, compute the network address by masking the IP with the subnet mask, and determine the number of host bits. Finally, iterate from 0 to 2^(host bits) - 1, adding each value to the network address to generate all IPs in order.
Pro tip: Clarify whether to include network and broadcast addresses; in most contexts, enumerating all addresses in the block includes them, but some may expect only usable hosts. Also, mention that for large blocks (e.g., /8), enumeration may be impractical, so consider lazy generation or streaming.
Split the input string on '/' to separate the IP address and prefix length. Convert the IP address into a 32-bit integer.
Calculate the subnet mask from the prefix length. Perform a bitwise AND between the IP and mask to get the network address. Compute the number of host bits as 32 minus the prefix length.
The number of addresses is 2^(host bits). Iterate from 0 to that number minus 1, representing all possible host-bit combinations.
For each host value, add it to the network address (bitwise OR) to get the current IP as an integer. Convert the integer back to dotted-decimal format and output or store it.
Consider edge cases like /32 (single address) and /31 (two addresses). For large blocks, discuss memory and time trade-offs, possibly using a generator to yield addresses lazily.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.