Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
from typing import List
from .net_cidr_cidr_info import cidr_info
from .net_ipv4 import format_ipv4, parse_ipv4 ← from net.ipv4 ^1.0.0 · built alongside by fune
def cidr_hosts(cidr: str, max_count: int) -> List[str]:
"""Every usable host address of an IPv4 block, in order, for a sweep.
The limit is required, not optional: a typo of /8 for /28 is sixteen
million addresses, and the caller should hear about it before allocating
them.
"""
if isinstance(max_count, bool) or not isinstance(max_count, int) or max_count < 1:
raise ValueError("maxCount must be a whole number of at least 1, received %r" % (max_count,))
info = cidr_info(cidr)
if info.host_count > max_count:
raise ValueError("%s has %d hosts, more than maxCount %d" % (info.cidr, info.host_count, max_count))
first = parse_ipv4(info.first_host)
return [format_ipv4(first + i) for i in range(info.host_count)]