Skip to content

Instantly share code, notes, and snippets.

@cordx56
Last active December 5, 2018 15:06
Show Gist options
  • Save cordx56/71cd6d30e87ca7aab5b43f64b757a2dc to your computer and use it in GitHub Desktop.
Save cordx56/71cd6d30e87ca7aab5b43f64b757a2dc to your computer and use it in GitHub Desktop.
Student ID card reader using Python2 & nfcpy
#!/usr/bin/env python2
import nfc
def on_connect(tag):
print '\n'.join(tag.dump())
with nfc.ContactlessFrontend('usb') as clf:
clf.connect(rdwr={'on-connect': on_connect})
#!/usr/bin/env python2
from idreader import IDReader
def printid(studentid, afrom, ato):
print("ID: " + studentid)
print("from: " + afrom + ", to: " + ato)
idr = IDReader(printid)
idr.read()
#!/usr/bin/env python2
import nfc
class IDReader:
callback = None
def __init__(self, cbfunc):
self.callback = cbfunc
def on_connect(self, tag):
try:
sc1 = nfc.tag.tt3.ServiceCode(4, 0x010B)
bc1 = nfc.tag.tt3.BlockCode(0, service=0)
data = tag.read_without_encryption([sc1], [bc1])
studentid = data[3:10]
bc1 = nfc.tag.tt3.BlockCode(1, service=0)
data = tag.read_without_encryption([sc1], [bc1])
afrom = data[0:8]
ato = data[8:16]
self.callback(studentid, afrom, ato)
except nfc.tag.TagCommandError as e:
print("NFC tag read error")
def read(self):
with nfc.ContactlessFrontend('usb') as clf:
clf.connect(rdwr={'on-connect': self.on_connect})
#!/usr/bin/env python2
import nfc
def on_connect(tag):
try:
sc1 = nfc.tag.tt3.ServiceCode(4, 0x010B)
bc1 = nfc.tag.tt3.BlockCode(0, service=0)
data = tag.read_without_encryption([sc1], [bc1])
print "ID: " + data[3:10]
bc1 = nfc.tag.tt3.BlockCode(1, service=0)
data = tag.read_without_encryption([sc1], [bc1])
print "from: " + data[0:8] + ", to: " + data[8:16]
except nfc.tag.TagCommandError as e:
print("NFC tag read error")
def main():
with nfc.ContactlessFrontend('usb') as clf:
clf.connect(rdwr={'on-connect': on_connect})
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment