Created
May 12, 2018 15:43
-
-
Save gmacon/5145678ebfa808b4905215f58f1769ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ipaddress | |
import hypothesis.strategies as S | |
@S.compound | |
def ip4_networks(draw): | |
prefixlen = draw(S.integers(min_value=0, max_value=32)) | |
if prefixlen: | |
network_bits = draw(S.integers(min_value=0, max_value=(1 << prefixlen) - 1)) | |
else: | |
network_bits = 0 | |
network = network_bits << (32 - prefixlen) | |
return ipaddress.IPv4Network((network, prefixlen)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment