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

Since Python 3.3 there is an ipaddress module in the stdlib that you can use.

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

If using Python 2.6 or higher I would strongly recommend to use a backport of this module.

Leave a Comment