Wouter van Reeven
Wouter van Reeven

Reputation: 545

Read serial id mifare with pyscard

I am trying everything to read a serial id with a mifare card. I can use the atr from pyscard. But he will give the same id when i am using mulitiple cards.

Or do i write data on a mifare card. But how can i do this. I am useing the python script on a ubuntu server. My cardreader is a acr122u.

Please it will be very helpful

Thanks

Upvotes: 4

Views: 8559

Answers (3)

pix
pix

Reputation: 5070

Here is some quick and dirty python code that uses pyscard and prints the UID (with assertions in lieu of actual error handling) by sending the APDU from Patrick's answer.

from smartcard.scard import *

hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER)

assert hresult==SCARD_S_SUCCESS

hresult, readers = SCardListReaders(hcontext, [])

assert len(readers)>0

reader = readers[0]

hresult, hcard, dwActiveProtocol = SCardConnect(
    hcontext,
    reader,
    SCARD_SHARE_SHARED,
    SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1)

hresult, response = SCardTransmit(hcard,dwActiveProtocol,[0xFF,0xCA,0x00,0x00,0x00])

print(response)

Upvotes: 3

Patrick
Patrick

Reputation: 51

You should use APDU commands for this to work. The command to get UID is 0xFF,0xCA,0x00,0x00,0x00 in case of a mifare card.

Follow this link and look under high level api. This should give you an idea.

Upvotes: 5

Wouter van Reeven
Wouter van Reeven

Reputation: 545

The best way to use is pyscard (Python module) or Java Smart Card I/O (part of Java JDK)

Upvotes: 0

Related Questions