forked from LudovicRousseau/PCSC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getAttrib.py
executable file
·61 lines (50 loc) · 2.3 KB
/
getAttrib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#! /usr/bin/env python
"""
# getAttrib.py : Unitary test for SCardGetAttrib()
# Copyright (C) 2011 Ludovic Rousseau
"""
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, see <https://www.gnu.org/licenses/>.
from __future__ import print_function
from smartcard.System import readers
from smartcard.scard import (SCARD_ATTR_VENDOR_NAME, SCARD_SHARE_DIRECT,
SCARD_LEAVE_CARD, SCARD_ATTR_DEVICE_FRIENDLY_NAME,
SCARD_ATTR_VENDOR_IFD_VERSION, SCARD_ATTR_VENDOR_IFD_SERIAL_NO)
import smartcard.Exceptions
def main():
""" Ask the first reader/driver to return its Vendor Name if any """
card_connection = readers()[0].createConnection()
card_connection.connect(mode=SCARD_SHARE_DIRECT,
disposition=SCARD_LEAVE_CARD)
try:
# Vendor name
name = card_connection.getAttrib(SCARD_ATTR_VENDOR_NAME)
print(''.join([chr(char) for char in name]))
# Vendor-supplied interface device version (DWORD in the form
# 0xMMmmbbbb where MM = major version, mm = minor version, and
# bbbb = build number).
version = card_connection.getAttrib(SCARD_ATTR_VENDOR_IFD_VERSION)
print("Version: %d.%d.%d" % (version[3], version[2],
version[0]))
# Vendor-supplied interface device serial number.
# only for readers with a USB serial number
serial = card_connection.getAttrib(SCARD_ATTR_VENDOR_IFD_SERIAL_NO)
print(serial)
# Reader's display name
# only with pcsc-lite version >= 1.6.0
name = card_connection.getAttrib(SCARD_ATTR_DEVICE_FRIENDLY_NAME)
print(''.join([chr(char) for char in name]))
except smartcard.Exceptions.SmartcardException, message:
print("Exception:", message)
if __name__ == "__main__":
main()