Reading Data from MIFARE Tag with PyNFC

  • Share this:

Code introduction


This function uses the PyNFC library to read data from a MIFARE tag. It first connects to the tag, selects the tag, requests access permissions, then reads the data from block 1, and finally disconnects from the tag.


Technology Stack : PyNFC library, MIFARE tag communication

Code Type : The type of code

Code Difficulty :


                
                    
def read_mifare_tag(reader):
    """
    Read data from a MIFARE tag using PyNFC reader.

    :param reader: An instance of PyNFC reader
    :return: The data read from the MIFARE tag
    """
    # Connect to the tag
    reader.connect()
    # Select the tag
    reader.aim(0x00)
    # Request access
    response = reader.交易([0x52, 0x00, 0x00, 0x00])
    # Read block 1
    data = reader.交易([0x30, 0x00, 0x00, 0x00])
    # Disconnect from the tag
    reader.disconnect()
    return data[1]