Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from smartcard.System import readers
- from smartcard.util import toHexString
- from colorama import init, Fore, Style
- import time
- # Initialize colorama
- init(autoreset=True)
- def detect_reader():
- r = readers()
- if len(r) > 0:
- print(Fore.GREEN + "Reader detected: " + str(r[0]))
- return r[0]
- else:
- print(Fore.RED + "No reader detected")
- return None
- def detect_card(reader):
- connection = reader.createConnection()
- try:
- connection.connect()
- print(Fore.GREEN + "Card detected")
- except:
- print(Fore.RED + "No card detected initially")
- return
- while True:
- try:
- connection.connect()
- response, sw1, sw2 = connection.transmit([0xFF, 0xCA, 0x00, 0x00, 0x00])
- if sw1 == 0x90 and sw2 == 0x00:
- print(Fore.GREEN + "Card present, UID: " + toHexString(response))
- else:
- print(Fore.RED + "Card present but failed to read UID")
- except:
- print(Fore.RED + "No card detected")
- time.sleep(1)
- if __name__ == "__main__":
- reader = detect_reader()
- if reader:
- try:
- detect_card(reader)
- except KeyboardInterrupt:
- print(Fore.YELLOW + "\nProgram interrupted and stopped by user.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement