Python Forum
len() of ipaddress.ip_network()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
len() of ipaddress.ip_network()
#3
I am not in familiar with ip addresses or networking stuff but I am not sure that it would be good idea to create sequence with 79228162514264337593543950336 elements (you need one to determine len).

Skimming documentation I found iterators:

hosts() (Returns an iterator over the usable hosts in the network.)

ipaddress.summarize_address_range(first, last) (Return an iterator of the summarized network range given the first and last IP addresses.)

One can always do simple math:

>>> int(ipaddress.IPv4Address('127.0.0.5')) - int(ipaddress.IPv4Address('127.0.0.1'))
4
>>> int(ipaddress.IPv6Address('1::'))
5192296858534827628530496329220096
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
len() of ipaddress.ip_network() - by Skaperen - May-17-2019, 03:49 AM
RE: len() of ipaddress.ip_network() - by heiner55 - May-17-2019, 05:33 AM
RE: len() of ipaddress.ip_network() - by perfringo - May-17-2019, 06:21 AM
RE: len() of ipaddress.ip_network() - by Skaperen - May-17-2019, 07:13 PM
RE: len() of ipaddress.ip_network() - by perfringo - May-18-2019, 06:25 AM
RE: len() of ipaddress.ip_network() - by Skaperen - May-18-2019, 11:14 PM
RE: len() of ipaddress.ip_network() - by DeaD_EyE - May-18-2019, 09:58 AM
RE: len() of ipaddress.ip_network() - by Skaperen - May-19-2019, 12:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  module ipaddress Skaperen 2 2,451 Aug-14-2018, 05:59 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020