def is_magic_packet(data):
    """
    Checks if a packet is a magic packet, returns
    True or False.

    Args:
        data (bytes): the payload from a packet

    """
    # convert data to lowercase hex string
    data = data.hex().lower()

    # magic packets begin with 'f'*12 (called a synchronization stream)
    sync = data[:12]

    if sync == 'f'*12:
        # the mac address follows (next 12 chars)
        mac = data[12:24]

        # and the mac address is repeated 16 times
        magic = sync + mac*16

        if len(data) == len(magic):
            return magic == data
        else:
            # allow for a SecureON password, which adds another
            # 12-character hex string to the end of the packet
            return magic == data[:-12]
    else:
        return False