2 ms·
Thanks, 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)
by gorgoiler 6y ago
Thanks, 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.