Issue 51 in netaddr: __iter__ operator for IPv6 network

18 views
Skip to first unread message

codesite...@google.com

unread,
Nov 26, 2009, 12:58:17 PM11/26/09
to net...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 51 by pgurumur: __iter__ operator for IPv6 network
http://code.google.com/p/netaddr/issues/detail?id=51

Python 2.5.4 (r254:67916, Jul 3 2009, 22:17:21)
[GCC 3.3.5 (propolice)] on openbsd4
Type "help", "copyright", "credits" or "license" for more information.
>>> from netaddr import IPNetwork
>>> test = IPNetwork("fd91:f405:c161:6f7a::/64")
>>> print test
fd91:f405:c161:6f7a::/64
>>> list(test)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/usr/local/lib/python2.5/site-packages/netaddr-0.7.3-py2.5.egg/netaddr/ip/__init__.py",
line 931, in __len__
"IP addresses! Use the .size property instead." % _sys.maxint)
IndexError: range contains more than 9223372036854775807 (sys.maxint) IP
addresses! Use the .size property instead.


How would I go about getting a list? or is it not possible?


--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

codesite...@google.com

unread,
Nov 26, 2009, 5:16:06 PM11/26/09
to net...@googlegroups.com
Updates:
Status: WontFix

Comment #1 on issue 51 by drkjam: __iter__ operator for IPv6 network
http://code.google.com/p/netaddr/issues/detail?id=51

Using list() on a /64 IPv6 network wouldn't be wise as it would chew up all
the
memory on your system and/or take a *very* long time to complete.

When dealing with networks containing more than sys.maxint (2^31) addresses
use the
.size property (as suggested by Exception message) to find out how many
addresses are
within a given range and the iterator protocol to access to all addresses
within it
in an in an efficient way, the simplest being :-

>>> for ip in IPNetwork("fd91:f405:c161:6f7a::/64"):
... # do something with your address

OR something like :-

>>> it = iter(IPNetwork("fd91:f405:c161:6f7a::/64"))
>>> ip = it.next()
IPAddress("fd91:f405:c161:6f7a::")

HTH
Reply all
Reply to author
Forward
0 new messages