The Python ipaddress module

The ipaddress module simplifies working with IPv4 and IPv6 addresses in python. In this section, we will focus on the IPv6 protocol and work primarily with the following three class types:

  • IPv6Address: Represents a single IPv6 address
  • IPv6Network: Represents an IPv6 network
  • IPv6Interface: Represents an IPv6 interface

You can get more information about this module with the help command from the Python interpreter:

The IPv6Address class represents an IPv6 address or network. To create these objects in Python, the module provides some basic factory functions to create such objects:

import ipaddress
from ipaddress import IPv6Address, IPv6Network, IPv6Interface

After you create an IPv6 object, you can get a lot of information out of the class, for example, whether it is a global or private address, the prefix length, and netmask.

In this screenshot, we can see the methods you can employ to check these use cases:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset