phihag / ipaddress

Python 3.3+'s ipaddress for older Python versions
Other
104 stars 53 forks source link

class IPv4Network hosts function does not work when prefixlen is /31 #58

Open sli35 opened 4 years ago

sli35 commented 4 years ago

Normally, the class IPv4Network "hosts" function is modified to "iter" when mask is /31. This works well when the network is a string, however when the network is an integer, it does not work.

In the init function of the class, there are two conditions upon which the hosts function is not adjusted:

if isinstance(address, (_compat_int_types, bytes)):

if isinstance(address, tuple):

Modification of hosts, only applies when both conditions are failing:

if self._prefixlen == (self._max_prefixlen - 1): self.hosts = self.iter

The problem has been discovered when using exclude_address, the result is an iterator of IPv4Network objects created using integers. hosts function does not work when one of the remaining IPv4Network is a /31.

frenzymadness commented 3 years ago

Is this problem already fixed in CPython ipaddress module? If not, it might make sense to open a bug report on https://bugs.python.org/