import ipaddress


def ip_is_loopback(ip):
    """Return whether an IP address is on the loopback interface"""
    ip = ipaddress.ip_address(ip)
    if ip.version == 6 and ip.ipv4_mapped is not None:
        ip = ip.ipv4_mapped
    return ip.is_loopback