Python – check if ip is public or private


netaddr is a Python library for representing and manipulating network addresses.

Installing netaddr library:

Use any of following command to install netaddr library

$ sudo pip install netaddr
$ easy_install netaddr

Observe following example for more details:

>>> from netaddr import *
>>> IPAddress('').is_private()
>>> IPAddress('').is_private()
>>> IPAddress('').is_loopback()

IPAddress(‘input ip’).is_private() will return true if the input ip address private, else it will return false.

Reference: Netaddr

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s