##Check for invalid outputs, and regenerate them.
Check for invalid outputs, and regenerate them.
It's possible that you'll produce an output that's reserved for a particular purpose, such as loopback (127.0.0.1 or ::1) or broadcast (255.255.255.255, ff02::1, ff02::2). Build in knowledge of such addresses, and if you find you've produced one, then replace it. You can do that recursively:
def make_address(v):
address = random_ip(v)
if is_reserved(address):
return make_address(v)
return address