Skip to content

Commit 1243c7d

Browse files
author
Peter Moody
committed
Issue #19157: Include the broadcast address in the usuable hosts for IPv6
in ipaddress.
1 parent 11a4270 commit 1243c7d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Lib/ipaddress.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,6 +2155,18 @@ def __init__(self, address, strict=True):
21552155
if self._prefixlen == (self._max_prefixlen - 1):
21562156
self.hosts = self.__iter__
21572157

2158+
def hosts(self):
2159+
"""Generate Iterator over usable hosts in a network.
2160+
2161+
This is like __iter__ except it doesn't return the
2162+
Subnet-Router anycast address.
2163+
2164+
"""
2165+
network = int(self.network_address)
2166+
broadcast = int(self.broadcast_address)
2167+
for x in range(network + 1, broadcast + 1):
2168+
yield self._address_class(x)
2169+
21582170
@property
21592171
def is_site_local(self):
21602172
"""Test if the address is reserved for site-local.

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Core and Builtins
2020
Library
2121
-------
2222

23+
- Issue #19157: Include the broadcast address in the usuable hosts for IPv6
24+
in ipaddress.
25+
2326
- Issue #20875: Prevent possible gzip "'read' is not defined" NameError.
2427
Patch by Claudiu Popa.
2528

0 commit comments

Comments
 (0)