Python Tool For ACR122U NFC Reader-Writer (VERY GOOD)
Python Tool For ACR122U NFC Reader-Writer (VERY GOOD)
Enviroment
pyscard 1.9.4
python 2.7.10
mute: Disable beep sound when card is tagged. (This setting is volatile. Lasts till
device off.)
loadkey <key>: Load key <key> (6byte hexstring) for auth. (The loaded key is
volatile. Lasts till device off.)
Load key with 'loadkey' command (This procedure is not needed for MIFARE
Ultralight)
TODO
Make options for 'read' command
Copyright
Copyright © 2016 Kim Dong Min.
if len(sys.argv) < 2:
print "usage: nfcTool.py <command>\nList of available commands: help, mute,
unmute, getuid, info, loadkey, read, firmver"
sys.exit()
r = readers()
if len(r) < 1:
print "error: No readers available!"
sys.exit()
reader = r[0]
print "Using: ", reader
connection = reader.createConnection()
connection.connect()
#detect command
cmd = sys.argv[1]
if cmd == "help":
print "usage: python nfctool.py <command>\nList of available commands: help,
mute, unmute, getuid"
print "Before executing command, make sure that a card is being tagged on
the reader."
print "\thelp\tShow this help page"
print "\tmute\tDisable beep sound when card is tagged."
print "\tunmute\tEnable beep sound when card is tagged."
print "\tgetuid\tPrint UID of the tagged card."
print "\tinfo\tPrint card type and available protocols."
print "\tloadkey <key>\tLoad key <key> (6byte hexstring) for auth."
print "\tread <sector>\tRead sector <sector> with loaded key."
#print "\tread [-s <sector>] [-h | -a] [-d | -t] \tRead sector <sector> (or
all sectors) with loaded key. Print as [hex | ascii]. Print [data only | trailer
only]"
print "\tfirmver\tPrint the firmware version of the reader."
sys.exit()
cmdMap = {
"mute":[0xFF, 0x00, 0x52, 0x00, 0x00],
"unmute":[0xFF, 0x00, 0x52, 0xFF, 0x00],
"getuid":[0xFF, 0xCA, 0x00, 0x00, 0x00],
"firmver":[0xFF, 0x00, 0x48, 0x00, 0x00],
}
#send command
if type(COMMAND) == list:
data, sw1, sw2 = connection.transmit(COMMAND)
if cmd == "firmver":
print cmd +": "+ ''.join(chr(i) for i in data)+chr(sw1)+chr(sw2)
else:
print cmd + ": " + toHexString(data)
print "Status words: %02X %02X" % (sw1, sw2)
if (sw1, sw2) == (0x90, 0x0):
print "Status: The operation completed successfully."
elif (sw1, sw2) == (0x63, 0x0):
print "Status: The operation failed."
else:
print "error: Undefined command: "+ cmd +"\nUse \"help\" command for
command list."
sys.exit()