How to Get IPv4/IPv6 Address Range from CIDR in Python?

The following example code shows how to get IPv4 and IPv6 address range from CIDR in Python:

import ipaddress

def get_ip_range(cidr):
    net = ipaddress.ip_network(cidr)
    return net[0], net[-1]

cidr = ""
ip_range = get_ip_range(cidr)
print("Start ip = ", ip_range[0])
print("End ip = ", ip_range[1])
Start ip =
End ip =