###### tags: `ハッカソン` # インストール ラズパイは、sudoでインストールしないときちんとインストールされない。 ```shell= sudo pip3 install nfcpy ``` # PaSoRi 読み取り ```python= #!/usr/bin/env python # -*- coding: utf-8 -*- import os import sys sys.path.insert(1, os.path.split(sys.path[0])[0]) import binascii import nfc def connected(tag): if isinstance(tag, nfc.tag.tt3.Type3Tag): try: # 内容を16進数で出力する print(' ' + '\n '.join(tag.dump())) except Exception as e: print("error: %s" % e) else: print("error: tag isn't Type3Tag") # タッチ時のハンドラを設定して待機する clf = nfc.ContactlessFrontend('usb:054c:06c3') clf.connect(rdwr={'on-connect': connected}) ``` ``` Type3Tag 'FeliCa Standard (RC-SA00/1)' ID=012E4CD2F8852539 PMM=033242828247AAFF SYS=8365 System 8365 (unknown) Area 0000--FFFE Area 09C0--09FF Random Service 39: write with key & read w/o key (0x09C8 0x09CB) 0000: 30 31 47 50 32 30 41 30 38 37 00 00 00 00 30 31 |01GP20A087....01| ←学籍番号らしきもの 0001: c4 c9 d4 cf 20 d5 b3 c0 de b2 00 00 00 00 00 00 |.... ...........| 0002: 32 37 30 31 32 32 31 34 32 30 32 30 30 34 30 31 |2701221420200401| 0003: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| Area 0A00--0BBF Random Service 40: write with key & read w/o key (0x0A08 0x0A0B) 0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 0003: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| Random Service 41: write with key & read w/o key (0x0A48 0x0A4B) 0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| Cyclic Service 42: write with key & read w/o key (0x0A8C 0x0A8F) 0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 0004: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| Random Service 43: write with key & read w/o key (0x0AC8 0x0ACB) 0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| Cyclic Service 44: write with key & read w/o key (0x0B0C 0x0B0F) 0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 0015: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| Random Service 45: write w/o key (0x0B49) 0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| Random Service 46: write w/o key (0x0B89) 0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 0003: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| Area 0BC0--0BFF Random Service 47: write with key (0x0BC8) System FE00 (Common Area) Area 0000--FFFE Area 1A80--1AFF Area 1A81--1AFF Random Service 106: write with key & read w/o key (0x1A88 0x1A8B) 0000: 30 31 47 50 32 30 41 30 38 37 00 00 00 00 30 31 |01GP20A087....01| 0001: c4 c9 d4 cf 20 d5 b3 c0 de b2 00 00 00 00 00 00 |.... ...........| 0002: 32 37 30 31 32 32 31 34 32 30 32 30 30 34 30 31 |2701221420200401| 0003: 00 00 00 00 00 00 00 00 66 30 30 30 30 30 30 39 |........f0000009| Area 1B00--1B3F Area 1B01--1B3F Random Service 108: write with key & read with key (0x1B08 0x1B0A) Area 1B40--1B7F Area 1B41--1B7F Random Service 109: write with key & read with key (0x1B48 0x1B4A) Area 42C0--42FF Area 42C1--42FF Random Service 267: write with key & read with key (0x42C8 0x42CA) Area 4300--433F Area 4301--433F Random Service 268: write with key & read with key (0x4308 0x430A) Area 4340--437F Area 4341--437F Random Service 269: write with key & read w/o key (0x4348 0x434B) 0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 0002: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| Area 50C0--50FF Area 50C1--50FF Random Service 323: write with key & read w/o key (0x50C8 0x50CB) 0000: 66 15 20 13 72 01 08 00 00 00 00 00 00 00 00 00 |f. .r...........| 0001: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 0005: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| Cyclic Service 323: write with key & read w/o key (0x50CC 0x50CF) 0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 0009: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| Purse Service 323: direct with key & decrement with key & read w/o key (0x50D0 0x50D4 0x50D7) 0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| Area 7A00--7A3F Area 7A01--7A3F Random Service 488: write with key & read with key & read w/o key (0x7A08 0x7A0A 0x7A0B) 0000: 33 39 32 31 30 31 30 30 30 36 36 37 37 30 35 37 |3921010006677057| Area 7A40--7A7F Area 7A41--7A7F Random Service 489: write w/o key & read w/o key (0x7A49 0x7A4B) 0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000B: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| ``` ## 学籍番号だけを取り出す場合 ```python= #!/usr/bin/env python # -*- coding: utf-8 -*- import os import sys sys.path.insert(1, os.path.split(sys.path[0])[0]) import binascii import nfc service_code = 0x09CB def connected(tag): if isinstance(tag, nfc.tag.tt3.Type3Tag): try: sc = nfc.tag.tt3.ServiceCode(service_code >> 6 ,service_code & 0x3f) bc = nfc.tag.tt3.BlockCode(0,service=0) data = tag.read_without_encryption([sc],[bc]) print(data[2:10].decode("utf-8")) except Exception as e: print("error: %s" % e) else: print("error: tag isn't Type3Tag") # タッチ時のハンドラを設定して待機する clf = nfc.ContactlessFrontend('usb:054c:06c3') clf.connect(rdwr={'on-connect': connected}) ```