Read UID from HID iClass cards
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from smartcard.CardType import AnyCardType | |
from smartcard.CardRequest import CardRequest | |
from smartcard.util import toHexString, toBytes | |
from smartcard.CardMonitoring import CardMonitor, CardObserver | |
from smartcard.util import * | |
import urllib2 | |
import time | |
# a simple card observer that prints inserted/removed cards | |
class printobserver( CardObserver ): | |
"""A simple card observer that is notified | |
when cards are inserted/removed from the system and | |
prints its uids. The code is not pretty but it works! | |
""" | |
def update( self, observable, (addedcards, removedcards) ): | |
apdu = [0xff, 0xca, 0, 0, 0] | |
for card in addedcards: | |
try: | |
cardtype = AnyCardType() | |
cardrequest = CardRequest( timeout=1, cardType=cardtype ) | |
cardservice = cardrequest.waitforcard() | |
cardservice.connection.connect() | |
response, sw1, sw2 = cardservice.connection.transmit(apdu) | |
tagid = toHexString(response).replace(' ','') | |
print tagid | |
#urllib2.urlopen("http://your_web_servers_waiting_for_card_data/?uid=%s" % tagid, None, 3) | |
except Exception as e: | |
print "Exception detected: %s" % e | |
print "Card Monitor started..." | |
cardmonitor = CardMonitor() | |
cardobserver = printobserver() | |
cardmonitor.addObserver( cardobserver ) | |
while True: | |
time.sleep(3600) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment