0

我想获得智能卡的 ATR。我正在使用 HID omnikey 5321。我正在关注此链接“ http://pyscard.sourceforge.net/user-guide.html#requesting-any-card

到目前为止,我已经尝试过:

>>>from smartcard.CardType import AnyCardType
>>>from smartcard.CardRequest import CardRequest
>>>from smartcard.util import toHexString
>>>
>>> cardtype = AnyCardType()
>>> cardrequest = CardRequest( timeout=1, cardType=cardtype )
>>> cardservice = cardrequest.waitforcard() 
>>>
>>>>>> cardservice.connection.connect()

我在

cardservice.connection.connect() 

错误如:

raise CardConnectionException('Unable to connect with ptotocol[pcscprotocol] + . '+ScardGetErrorMessage(hresult) 
CardConnectionException: Unable to conenct the card with T0 or T1 . Card is not responding to reset.
4

2 回答 2

1

在 python 中,您可以使用 pyscard 库与智能卡进行交互,有一个示例可以帮助您在http://pyscard.sourceforge.net/pyscard-framework.html#framework-samples显示 ATR

于 2015-01-03T12:51:31.943 回答
0

因为您没有指定要连接的阅读器:

r=readers()
#r[Number of reader list].
cardservice.connection = r[0].createConnection()
cardservice.connection.connect()

一个简单的例子:

from __future__ import print_function
from smartcard.Exceptions import NoCardException
from smartcard.System import readers
from smartcard.util import toHexString

for reader in readers():
    try:
         connection = reader.createConnection()
         connection.connect()
         print(reader, toHexString(connection.getATR()))
    except NoCardException:
         print(reader, 'no card inserted')

import sys
if 'win32' == sys.platform:
    print('press Enter to continue')
    sys.stdin.read(1)

-另一个选择读者:

from __future__ import print_function
from smartcard.Exceptions import NoCardException
from smartcard.System import readers
from smartcard.util import toHexString
from smartcard.CardType import AnyCardType
from smartcard.CardRequest import CardRequest

cardtype = AnyCardType()
r=readers()
cardrequest = CardRequest( timeout=10, cardType=cardtype )
cardservice = cardrequest.waitforcard()
print('Available Readers:')
for i in range(len(readers())):
    print('[',i+1,']',r[i])
if(len(readers()) < 1):
    print("\nNO AVAILABLE READERS!\n")
else:
    print("Select you Reader: (Ctrl+C to Exit)")
    my_input = input()
    selectReader = clamp(int(my_input)-1,0,len(readers()))
    print('Selected: ',r[selectReader])
    cardservice.connection = r[selectReader].createConnection()
    cardservice.connection.connect()
    try:
        print('Card ATR:',toHexString(cardservice.connection.getATR()),file=f)
    except:
        print("Cant not Get ATR")

.

完整信息:

https://pyscard.sourceforge.io/pyscard-framework.html#framework-samples

https://github.com/LudovicRousseau/pyscard

https://pyscard.sourceforge.io/user-guide.html

于 2020-11-05T11:35:17.210 回答