如何从 HID 全能键获取 SMARD 卡的 ATR



我想获取智能卡的 ATR。我正在使用 HID 全能键 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.

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

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

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

相关内容

  • 没有找到相关文章

最新更新