import ipaddress


def get_ip_address(cfg_facts, port, ipver):
    """
    Gets the IP address of a port.

    Args:
        cfg_facts: Config facts for an asic.
        port: Port name.
        ipver: IP version, 4 or 6.

    Returns:
        an ipaddress.IPAddress() for the port.

    """

    intfs = {}
    intfs.update(cfg_facts.get('INTERFACE', {}))
    if "PORTCHANNEL_INTERFACE" in cfg_facts:
        intfs.update(cfg_facts['PORTCHANNEL_INTERFACE'])

    addresses = intfs[port]
    for address in addresses:
        intf = ipaddress.ip_interface(address)
        if intf.ip.version == ipver:
            return intf.ip