Advertisement
Manu-J

ACR122-U9

May 16th, 2024
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. from smartcard.System import readers
  2. from smartcard.util import toHexString
  3. from colorama import init, Fore, Style
  4. import time
  5.  
  6. # Initialize colorama
  7. init(autoreset=True)
  8.  
  9. def detect_reader():
  10.     r = readers()
  11.     if len(r) > 0:
  12.         print(Fore.GREEN + "Reader detected: " + str(r[0]))
  13.         return r[0]
  14.     else:
  15.         print(Fore.RED + "No reader detected")
  16.         return None
  17.  
  18. def detect_card(reader):
  19.     connection = reader.createConnection()
  20.    
  21.     try:
  22.         connection.connect()
  23.         print(Fore.GREEN + "Card detected")
  24.     except:
  25.         print(Fore.RED + "No card detected initially")
  26.         return
  27.  
  28.     while True:
  29.         try:
  30.             connection.connect()
  31.             response, sw1, sw2 = connection.transmit([0xFF, 0xCA, 0x00, 0x00, 0x00])
  32.             if sw1 == 0x90 and sw2 == 0x00:
  33.                 print(Fore.GREEN + "Card present, UID: " + toHexString(response))
  34.             else:
  35.                 print(Fore.RED + "Card present but failed to read UID")
  36.         except:
  37.             print(Fore.RED + "No card detected")
  38.  
  39.         time.sleep(1)
  40.  
  41. if __name__ == "__main__":
  42.     reader = detect_reader()
  43.     if reader:
  44.         try:
  45.             detect_card(reader)
  46.         except KeyboardInterrupt:
  47.             print(Fore.YELLOW + "\nProgram interrupted and stopped by user.")
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement