views:

239

answers:

2

I have got to be doing something wrong here... I am at present trying to validate whether an ip is within a specific subnet utilizing a builtin module.

I am using activepython:

ActivePython 3.1.2.3 (ActiveState Software Inc.) based on
Python 3.1.2 (r312:79147, Mar 22 2010, 12:20:29) [MSC v.1500 32 bit (Intel)] on win32

which has this in the changelog:

Python News
(editors: check NEWS.help for information about editing NEWS using ReST.)

What's New in Python 3.1.2?
Release date: 2010-03-20

----- snip -----

Removed the ipaddr module. 
Issue #3613: base64.{encode,decode}string are now called 
System Message: WARNING/2 (, line 706)

----- snip -----

Issue #3959: The ipaddr module has been added to the standard library. Contributed by Google.

that and other google searches have led me to believe that ipaddr was a builtin and yet:

>>> import ipaddr
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named ipaddr
>>> from ipaddr import *
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named ipaddr

so i figured i would install netaddr and attempt to use that and all i get from netaddr is:

>>> import netaddr
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python31\lib\site-packages\netaddr\__init__.py", line 18, in 
    from netaddr.ip import IPAddress, IPNetwork, IPRange, all_matching_cidrs, \
  File "C:\Python31\lib\site-packages\netaddr\ip\__init__.py", line 1877, in 
    IPV6_LOOPBACK = IPAddress('::1')
  File "C:\Python31\lib\site-packages\netaddr\ip\__init__.py", line 262, in __init__
    self.value = addr
  File "C:\Python31\lib\site-packages\netaddr\ip\__init__.py", line 292, in _set_value
    % value)
netaddr.core.AddrFormatError: failed to detect IP version: '::1'

I am feeling fairly frustrated and i'm not sure where to go from here... suggestions?

+1  A: 

the ipaddr module was added in the 3.1 development cycle (between alpha 2 and beta 1), but removed before the first release candidate of 3.1. It's not part of the standard library of any released Python version. You can still download and install it from, for example, PyPI.

The netaddr failure seems to be a bug in netaddr itself. It tries to detect IPv6 support and fails. I'd guess it's a bug in the module, but a fix or workaround is harder to guess at.

Thomas Wouters
A: 

netaddr doesn't support Python 3.x yet (as mentioned in the README).

However, it will do in the forthcoming release (0.7.5). I'll take this as a hint that I should hurry up and get it out the door!

I've added a ticket on the project bug tracker here :-

http://code.google.com/p/netaddr/issues/detail?id=55

Thanks.

David Moss