4 ms·
Unless I misunderstand what you're looking for, I think that functionality is in there. original_net_48 = ip_network("2a00:aaaa:bbbb::/48") desired_sub
by chc 6y ago
Unless I misunderstand what you're looking for, I think that functionality is in there.
original_net_48 = ip_network("2a00:aaaa:bbbb::/48")
desired_subnet = ip_network('2a00:aaaa:bbbb:cccc::/64')
subnets_64 = original_net_48.subnets(16)
print(f"{desired_subnet} is one of the computed subnets: {desired_subnet in subnets_64}")
#=> 2a00:aaaa:bbbb:cccc::/64 is one of the computed subnets: True
- gorgoiler 6y agoThanks, but your second line kind of has the answer in it already. It’s more like... site = ip_network(‘2a00:aaaa:bbbb::/48’) subnet = f(site, 64, 0xcccc) ...and I don’t think f() is in the standard library. But maybe I just index the calculated subnets, from your example? I’ll give it a go! Edit: yes! But it’s a bit slow... https://repl.it/repls/PoshPapayawhipNaturaldocs#main.py https://repl.it/repls/PoshPapayawhipNaturaldocs#main.py
- xxpor 6y agoWell, you can speed it up slightly by using the iterator directly instead of forcing the whole generator into a list. But on the other hand, you can make it WAY faster by doing it with bit manipulation instead like you're writing C: https://repl.it/repls/ClearcutElaborateEmbeds https://repl.it/repls/ClearcutElaborateEmbeds
- chc 6y agoOh, yeah, you're right. That's a shame — that function does exactly what you want, but it has to do it for every possible subnet up to the one you want, and the logic isn't included as a separate function.