Advertisement
valdur55

minimal-leak.py

Feb 8th, 2017
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.15 KB | None | 0 0
  1.  #! /usr/bin/env python
  2. """
  3. Sample script that monitors smartcard insertion/removal.
  4.  
  5. __author__ = "http://www.gemalto.com"
  6.  
  7. Copyright 2001-2012 gemalto
  8. Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com
  9.  
  10. This file is part of pyscard.
  11.  
  12. pyscard is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU Lesser General Public License as published by
  14. the Free Software Foundation; either version 2.1 of the License, or
  15. (at your option) any later version.
  16.  
  17. pyscard is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU Lesser General Public License for more details.
  21.  
  22. You should have received a copy of the GNU Lesser General Public License
  23. along with pyscard; if not, write to the Free Software
  24. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  25. """
  26.  
  27. from __future__ import print_function
  28. from time import sleep
  29.  
  30. from smartcard.CardMonitoring import CardMonitor, CardObserver
  31. from smartcard.util import toHexString
  32.  
  33.  
  34. # a simple card observer that prints inserted/removed cards
  35. class PrintObserver(CardObserver):
  36.     """A simple card observer that is notified
  37.    when cards are inserted/removed from the system and
  38.    prints the list of cards
  39.    """
  40.  
  41.     def update(self, observable, actions):
  42.         (addedcards, removedcards) = actions
  43.         for card in addedcards:
  44.             print("+Inserted: ", toHexString(card.atr))
  45.         for card in removedcards:
  46.             print("-Removed: ", toHexString(card.atr))
  47.  
  48. if __name__ == '__main__':
  49.     print("Insert or remove a smartcard in the system.")
  50.     print("This program will run forever")
  51.     print("")
  52.     cardmonitor = CardMonitor()
  53.     cardobserver = PrintObserver()
  54.     cardmonitor.addObserver(cardobserver)
  55.  
  56.     while True:
  57.         sleep(1)
  58.  
  59.     # don't forget to remove observer, or the
  60.     # monitor will poll forever...
  61.     cardmonitor.deleteObserver(cardobserver)
  62.  
  63.     import sys
  64.     if 'win32' == sys.platform:
  65.         print('press Enter to continue')
  66.         sys.stdin.read(6000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement