Title: ipaddress.ip_network('').is_private == True
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Wicken, ammar2, pascalhofmann
Priority: normal Keywords:

Created on 2019-10-31 14:04 by pascalhofmann, last changed 2019-11-05 16:01 by Wicken.

Messages (5)
msg355753 - (view) Author: (pascalhofmann) Date: 2019-10-31 14:04
ipaddress.ip_network('').is_private returns True, even though clearly is no private network.
msg355998 - (view) Author: Ammar Askar (ammar2) * (Python triager) Date: 2019-11-05 05:06
The documentation for is_private notes:

  A boolean, True if the address is reserved per RFC 4193.
  iana-ipv4-special-registry or iana-ipv6-special-registry.

If we take a look at the iana-ipv4-special-registry then does show up there:

While the name might be a misnomer, is_reserved instead of is_private might have been better, it does seem to conform to what the documentation says it will do.
msg355999 - (view) Author: Ammar Askar (ammar2) * (Python triager) Date: 2019-11-05 05:09
Aah actually I was looking at an older version of the docs, the documentation now says, "if the address is allocated for private networks" which is actually misleading. The addresses here aren't all private networks:
msg356007 - (view) Author: (pascalhofmann) Date: 2019-11-05 07:11 is a network with addresses from to is a network with addresses from to

So 4278190080 out of 4294967296 addresses in clearly are no private addresses.
msg356044 - (view) Author: Pete Wicken (Wicken) * Date: 2019-11-05 16:01
Looks like this happens because the is_private method that gets called is from _BaseNetwork, which checks if the network address '' and the broadcast address '' are both private, which they are as falls into

I think for this to get it right, you would have to change the is_private check for networks to iterate over each possible subnet and check if that is in the private networks list. This takes an unfeasibly long time.

So, we would probably have to add special cases for these networks, unless people have better ideas.
Date User Action Args
2019-11-05 16:01:54Wickensetnosy: + Wicken
messages: + msg356044
2019-11-05 07:11:42pascalhofmannsetmessages: + msg356007
2019-11-05 05:09:49ammar2setmessages: + msg355999
2019-11-05 05:06:19ammar2setnosy: + ammar2
messages: + msg355998
2019-10-31 14:04:51pascalhofmanncreate