开发者

Python: listing IP ranges

I have problem with the netaddr package - version 0.7.5. This code works as expected and prints out th开发者_JAVA百科e list of ip addresses in the range:

from netaddr import IPNetwork

ipnetwork = '192.168.0.0/24'
print list(IPNetwork(ipnetwork).iter_hosts())

However, if I change the network to, say, '192.168.0.0/8' my script just hangs:

from netaddr import IPNetwork

ipnetwork = '192.168.0.0/8'
print list(IPNetwork(ipnetwork).iter_hosts())

Am I missing something or is this a bug?

EDIT

Looks like I was missing something by not realising how big that range is!


Are you sure that it's not just taking a lot of time? You are making a list out of the iterator. When I run that on my machine, I get 100% CPU usage and memory usage increase. I can also print out the entire range if I use the iterator directly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜