[issue42861] ipaddress - add ability to get next closet subnet of any prefix size
New submission from Faisal Mahmood : The ipaddress module in Python is an excellent tool, but I noticed it is missing a feature that I needed several months ago, which is the ability to find the next closest subnet with a specific prefix length. For example, imagine I had a IPv4Network("10.10.0.72/30"), how would I find the next possible /25 address? It is not the most straightforward thing to do, so think it would be a great enhancement to the ipaddress library. I think this can be achieved by adding in a new method to the BaseNetwork class, the method could be defined like "next_prefix(next_prefix=None)". Calling this method would return an IPv4/v6 address that is the closest possible match with the new prefix (defined as next_prefix). Example calls: v4 = IPv4Network("10.10.0.72/30") next_network = v4.next_subnet(next_prefix=25) # Output: next_network = IPv4Network("10.10.0.128/25") v4 = IPv4Network("10.10.0.72/30") next_network = v4.next_subnet(next_prefix=30) # Output: next_network = IPv4Network("10.10.0.76/30") v4 = IPv4Network("10.10.0.72/30") next_network = v4.next_subnet() # if next_prefix is not defined it will use the existing prefix of /30, so this call is exactly the same as the previous # Output: next_network = IPv4Network("10.10.0.76/30") v6 = IPv6Network("2001:db8::::::/112") next_network = v6.next_subnet() # Output: next_network = IPv6Network("2001:db8:::::aaab:0/112") v6 = IPv6Network("2001:db8::::::/112") next_network = v6.next_subnet(next_prefix=64) # Output: next_network = IPv6Network("2001:db8::aaab::/64") I am going to be working on this and plan to raise a PR soon. This is my first time contributing to Python, so I appreciate your help / comments / suggestions / guidance as I go along. -- components: Library (Lib) messages: 384623 nosy: fasial.mahmood94 priority: normal severity: normal status: open title: ipaddress - add ability to get next closet subnet of any prefix size type: enhancement versions: Python 3.10 ___ Python tracker <https://bugs.python.org/issue42861> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42861] ipaddress - add ability to get next closet subnet of any prefix size
Faisal Mahmood added the comment: Not sure how to edit an issue, but I made a mistake, where I said: "...Calling this method would return an IPv4/v6 address that is the closest possible match..." I meant to say: "...Calling this method would return an IPv4/v6 -NETWORK- that is the closest possible match..." -- ___ Python tracker <https://bugs.python.org/issue42861> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42861] ipaddress - add ability to get next closet network of any prefix size
Faisal Mahmood added the comment: Updated the title and method naming, I previously mentioned the "next subnet" and called the method "next_subnet", but technically this is wrong. What this method should be doing is finding the next closest network of prefix size n. So I guess the method definition should be: `next_network(self, next_network=None)` -- title: ipaddress - add ability to get next closet subnet of any prefix size -> ipaddress - add ability to get next closet network of any prefix size ___ Python tracker <https://bugs.python.org/issue42861> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42861] ipaddress - add ability to get next closet network of any prefix size
Change by Faisal Mahmood : -- keywords: +patch pull_requests: +23006 stage: -> patch review pull_request: https://github.com/python/cpython/pull/24180 ___ Python tracker <https://bugs.python.org/issue42861> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42861] ipaddress - add ability to get next closet network of any prefix size
Faisal Mahmood added the comment: Bump :) -- ___ Python tracker <https://bugs.python.org/issue42861> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com