Created
November 28, 2018 16:45
-
-
Save avisoftware/671916bfb74636837a17af65c67588ad to your computer and use it in GitHub Desktop.
RavKav Balance ** For test only **
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
$ python selectDEOfCard.py | |
insert a card (RavKav) within 10s | |
You have 1.8 NIS in your RavKav |
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
#!/usr/bin/python | |
""" | |
Licence: GPLv2 | |
Dependecies: | |
pcsc | |
swig | |
pyscard | |
""" | |
from __future__ import print_function | |
from smartcard.CardType import AnyCardType | |
from smartcard.CardRequest import CardRequest | |
from smartcard.CardConnectionObserver import ConsoleCardConnectionObserver | |
from smartcard.Exceptions import CardRequestTimeoutException | |
from smartcard.util import * | |
# define the apdus used in this script | |
GET_RESPONSE = [0XA0, 0XC0, 00, 00] | |
SELECT = [0x94, 0xA4, 0x00, 0x00, 0x02] | |
TICKETING_FOLDER = [0x20,0x00,0x00] | |
BALANCE_FILE = [0x20,0x2A,0x00] | |
READ_RECORD = [0x94,0xB2,0x01,0x04,0x1D] | |
#convert bytes to int | |
def byteStringToInt (bytes, offset, length): | |
if (len(bytes) < offset + length): | |
#err | |
return 0 | |
return int(bytes[offset:length*2],16) | |
# request any card type | |
cardtype = AnyCardType() | |
try: | |
# request card insertion | |
print('insert a card (RavKav) within 10s') | |
cardrequest = CardRequest(timeout=10, cardType=cardtype) | |
cardservice = cardrequest.waitforcard() | |
# attach the console tracer [for Debug] | |
observer = ConsoleCardConnectionObserver() | |
cardservice.connection.addObserver(observer) | |
# connect to the card and perform a transmits | |
cardservice.connection.connect() | |
apdu = SELECT + BALANCE_FILE | |
response, sw1, sw2 = cardservice.connection.transmit(apdu) | |
# there is a BALANCE_FILE | |
if sw1 == 0x90: | |
apdu = READ_RECORD | |
response, sw1, sw2 = cardservice.connection.transmit(apdu) | |
print("You have " + str(byteStringToInt(toHexString(response,PACK),0,3)/100) + " NIS in your RavKav") | |
else: | |
print('no BALANCE_FILE') | |
except CardRequestTimeoutException: | |
print('time-out: no card inserted during last 10s') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment