[Python-Dev] PEP 3144: IP Address Manipulation Library for the Python Standard Library
Case Vanhorsen
casevh at gmail.com
Fri Aug 21 07:15:59 CEST 2009
>On Thu, Aug 20, 2009 at 2:00 PM, Peter Moody<peter at hda3.com> wrote:
> The pep has been updated with the excellent suggestions thus far.
>
> Are there any more?
Thanks for writing the PEP.
I tried a few of the common scenarios that I use at work. Disclaimer:
my comments are based on my work environment.
I was surprised that IP('172.16.1.1') returned
IPv4Address('172.16.1.1/32') instead of IPv4Address('172.16.1.1'). I
know I can change the behavior by using host=True, but then
IP('172.16.1.1/24', host=True) will raise an error. It makes more
sense, at least to me, that if I input just an IP address, I get an IP
address back. I would prefer that IP('172.16.1.1/32') return an
IPv4Network and IP('172.16.1.1') return an IPv4Address.
Would it be possible to provide an iterator that returns just the
valid host IP addresses (minus the network and broadcast addresses)?
"for i in IPv4Network('172.16.1.0/28')" and "for in in
IPv4Network('172.16.1.0/28').iterhosts()" both return all 16 IP
addresses. I normally describe 172.16.1.0/28 as consisting of one
network address, 14 host addresses, and one broadcast address. I would
prefer that "for i in IPv4Network('172.16.1.0/28')" return all IP
addresses and that "for in in
IPv4Network('172.16.1.0/28').iterhosts()" exclude the network and
broadcast addresses. I think creating a list of IP addresses that can
be assigned to devices on a network is a common task.
Can .subnet() be enhanced to accept masks? For example,
IPv4Network('172.16.0.0/16').subnet('/19') would return the eight /19
subnets.
What about supporting multiple parameters to subnet? I frequently need
to create complex subnet layouts. The following subnet layout is NOT
made up!
172.16.0.0/22
>172.16.0.0/23
>>>172.16.2.0/25
>>>>172.16.2.128/26
>>>>172.16.2.192/26
>>>>>>172.16.3.0/28
>>>>>>172.16.3.16/28
>>>>>>>>172.16.3.32/30
>>>>>>>>172.16.3.36/30
>>>>>>>>172.16.3.40/30
>>>>>>>>172.16.3.44/30
>>>>>>>>172.16.3.48/30
>>>>>>>>172.16.3.52/30
>>>>>>>>172.16.3.56/30
>>>>>>>>172.16.3.60/30
>>>>>>>>>>172.16.3.64/32
....
>>>>>>>>>>172.16.3.79/32
>>>>>>172.16.3.80/28
>>>>>>172.16.3.96/28
>>>>>>172.16.3.112/28
>>>>>172.16.3.128/27
>>>>>172.16.3.160/27
>>>>172.16.3.192/26
A possible syntax would be:
.subnet((1,'/23'),(1,'/25'),(2,'/26'),(2,'/28'),(8,'/30'),(16,'/32'),(3,'/28'),(2,'/27'),(1,'/26'))
Note: I am willing to provide patches to implement my suggestions. I
just won't have much time over the next couple weeks.
casevh
> Cheers,
> /peter
>
> On Tue, Aug 18, 2009 at 1:00 PM, Peter Moody<peter at hda3.com> wrote:
>> Howdy folks,
>>
>> I have a first draft of a PEP for including an IP address manipulation
>> library in the python stdlib. It seems like there are a lot of really
>> smart folks with some, ahem, strong ideas about what an IP address
>> module should and shouldn't be so I wanted to solicit your input on
>> this pep.
>>
>> the pep can be found here:
>>
>> http://www.python.org/dev/peps/pep-3144/
>>
>> the code can be found here:
>>
>> http://ipaddr-py.googlecode.com/svn/branches/2.0.x/
>>
>> Please let me know if you have any comments (some already coming :)
>>
>> Cheers,
>> /peter
>>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/casevh%40gmail.com
>
More information about the Python-Dev
mailing list