Search code examples
pythonpython-3.xmoduleipip-address

Python3 Wrong IP Address Detection?


Reading this:

How do you determine if an IP address is private, in Python?

I wrote:

>>> import ipaddress
>>> ipaddress.ip_address('172.23.86.32').is_private
True

But that's not correct, this is a public IP address... how to fix this?


Solution

  • Your program is actually correct, 172.23.86.32 is a private IP address. Just check https://www.whatismyip.com/ or a similar service and you will see a different address (and that's your public address).

    See this wiki entry on IPv4 private network addresses: https://en.wikipedia.org/wiki/Private_network#Private_IPv4_addresses