from contextlib import suppress


def get_ip_layer(packet):
    """Return the IPv4 or IPv6 layer of a packet, if it exists. Otherwise None"""
    with suppress(IndexError):
        return packet['IP']
    with suppress(IndexError):
        return packet['IPv6']
    return None