Exploring netaddr methods

The netaddr module provides two important methods to define the IP address and work on it. The first one is called IPAddress() and it's used to define a single classful IP address with the default subnet mask. The second method is IPNetwork() and is used to define classless a IP address with CIDR.

Both methods take the IP address as a string and return an IP address or IP network object for this string. There are many operations that could be executed on the returned object. For example, we can check if the IP address is unicast, multicast, loopback, private, public, or even valid or not valid. The output of the previous operation is either True or False, which can be used inside Python if conditions.

Also, the module ...

Get Hands-On Enterprise Automation with Python. now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.