IPv4 to IPv6 conversion

There are multiple ways to convert an IPv4 address to an IPv6 address. In Python 3, we have the inbuilt ipaddress module:

import ipaddressdef convertusingipaddress(ipv4address):    print(ipaddress.IPv6Address('2002::' + ipv4address).compressed)convertusingipaddress("10.10.10.10")convertusingipaddress("192.168.100.1")

The output for the preceding code is as follows:

There are many different methods or functions in the ipaddress library that we can use for various purposes. The documentation and details can be found at https://docs.python.org/3/library/ipaddress.html.

Get Practical Network Automation 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.