Python 如何使NFC标签只读?
我有一张Python 如何使NFC标签只读?,python,python-3.x,nfc,access-control,lockbits,Python,Python 3.x,Nfc,Access Control,Lockbits,我有一张NTAG213NFC贴纸。我想知道怎样才能使这个贴纸成为只读的。如果以后切换到NTAG215,如何使该标记为只读。实际制作不同类型的只读标签所涉及的过程是什么。当我说只读时,我的意思是NFC的记录永远不能被修改,但是设备仍然可以在没有身份验证的情况下读取记录 我读过并试图实现它的解决方案 import nfc from time import sleep from nfc.clf import RemoteTarget import ndef clf = nfc.Contactless
NTAG213
NFC贴纸。我想知道怎样才能使这个贴纸成为只读的。如果以后切换到NTAG215
,如何使该标记为只读。实际制作不同类型的只读标签所涉及的过程是什么。当我说只读时,我的意思是NFC的记录永远不能被修改,但是设备仍然可以在没有身份验证的情况下读取记录
我读过并试图实现它的解决方案
import nfc
from time import sleep
from nfc.clf import RemoteTarget
import ndef
clf = nfc.ContactlessFrontend('usb')
while True:
target = clf.sense(RemoteTarget('106A'), RemoteTarget('106B'), RemoteTarget('212F'))
if target is None:
sleep(1)
continue
serial = target.sdd_res.hex()
tag = nfc.tag.activate(clf, target)
if not tag.ndef:
print("No NDEF records found!")
continue
for record in tag.ndef.records:
print("Found record: " + str(record))
record = ndef.UriRecord("https://www.example.com")
tag.ndef.records = [record]
# Code is fine until it gets to these tag indexes
tag[15] = tag[15] | 0x0F
tag[10] = 0xFF
tag[11] = 0xFF
我得到一个错误:
File "test.py", line 26, in <module>
tag[15] = tag[15] | 0x0F
TypeError: 'NTAG213' object does not support indexing
文件“test.py”,第26行,在
标签[15]=标签[15]| 0x0F
TypeError:“NTAG213”对象不支持索引
查看Python库,它有一个简单的方法,可以使用锁字节或通过密码使其成为只读
只需在带有或不带密码的标记
对象上调用protect
方法(不带密码使用锁定字节,并且是永久只读的)
因此,库中已为各种卡(包括所有NTAG21x卡)编程了正确的内存地址和翻转位。所有详细信息都在卡的数据表中。有多种方法可以写入正确的内存位置以更改锁定位,有两种方法可以永久使内存为只读(不同内存区域各有一个)或者更好的方法是密码保护写操作(因为如果知道密码,这可以反转)
标记是一个类,而不是数组。不能通过数组索引访问类。必须使用此类(或API)中定义的函数。