Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 142 lines (121 sloc) 3.174 kb
447c384 first commit
Adam Laurie authored
1 #!/usr/bin/python
2
3 # readmifareultra.py - read all sectors from a Ultralight tag
4 #
5 # Keith Howell <kch@kch.net>
6 # built on the code by:
7 # Adam Laurie <adam@algroup.co.uk>
8 # http://rfidiot.org/
9 #
10 # This code is copyright (c) Adam Laurie, 2006, All rights reserved.
11 # For non-commercial use only, the following terms apply - for all other
12 # uses, please contact the author:
13 #
14 # This code is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
18 #
19 # This code is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
23 #
24
25
271cf40 @AdamLaurie more package changes - be sure to read INSTALL for small but importan…
authored
26 import rfidiot
447c384 first commit
Adam Laurie authored
27 import sys
28 import os
29
30 try:
271cf40 @AdamLaurie more package changes - be sure to read INSTALL for small but importan…
authored
31 card= rfidiot.card
447c384 first commit
Adam Laurie authored
32 except:
271cf40 @AdamLaurie more package changes - be sure to read INSTALL for small but importan…
authored
33 print "Couldn't open reader!"
447c384 first commit
Adam Laurie authored
34 os._exit(True)
35
271cf40 @AdamLaurie more package changes - be sure to read INSTALL for small but importan…
authored
36 help= rfidiot.help
447c384 first commit
Adam Laurie authored
37
38 if help:
39 print sys.argv[0] + ' - read mifare ultralight tags'
40 print 'Usage: ' + sys.argv[0]
41 print
42 os._exit(True)
43
271cf40 @AdamLaurie more package changes - be sure to read INSTALL for small but importan…
authored
44 card.info('readmifareultra v0.1b')
447c384 first commit
Adam Laurie authored
45 card.waitfortag('Waiting for Mifare Ultralight...')
46
47 blocks=16
48
49 print '\n ID: ' + card.uid
50 print 'Type: ' + card.tagtype
51
52 card.select()
53 # pull header block information from the tag
54 if card.readblock(0):
55 sn0=card.data[0:2]
56 sn1=card.data[2:4]
57 sn2=card.data[4:6]
58 bcc0=card.data[6:8]
59 else:
60 print 'read error: %s' % card.errorcode
61
62 if card.readblock(1):
63 sn3=card.data[0:2]
64 sn4=card.data[2:4]
65 sn5=card.data[4:6]
66 sn6=card.data[6:8]
67 else:
68 print 'read error: %s' % card.errorcode
69
70 if card.readblock(2):
71 bcc1=card.data[0:2]
72 internal=card.data[2:4]
73 lock0=card.data[4:6]
74 lock1=card.data[6:8]
75 else:
76 print 'read error: %s' % card.errorcode
77
78 if card.readblock(3):
79 otp0=card.data[0:2]
80 otp1=card.data[2:4]
81 otp2=card.data[4:6]
82 otp3=card.data[6:8]
83 else:
84 print 'read error: %s' % card.errorcode
85
86 # convert lock bytes to binary for later use
87 lbits0=card.ToBinaryString(card.ToBinary(lock0))
88 lbits1=card.ToBinaryString(card.ToBinary(lock1))
89 lbits=lbits1 + lbits0
90
91 y=0
92 plock=''
93 for x in range(15,-1,-1):
94 plock = lbits[y:y+1] + plock
95 y += 1
96
97 # show status of the OTP area on the tag
98 print 'OTP area is',
99 if int(plock[3:4]) == 1:
100 print 'locked and',
101 else:
102 print 'unlocked and',
103 if int(plock[0:1]) == 1:
104 print 'cannot be changed'
105 else:
106 print 'can be changed'
107
108 print 'If locked, blocks 4 through 9',
109 if int(plock[1:2]) == 1:
110 print 'cannot be unlocked'
111 else:
112 print 'can be unlocked'
113
114 print 'If locked, blocks 0a through 0f',
115 if int(plock[2:3]) == 1:
116 print 'cannot be unlocked'
117 else:
118 print 'can be unlocked'
119
120 print '\nTag Data:'
121 # DATA0 byte starts on page/block 4
122 for x in range(blocks):
123 print ' Block %02x:' % x,
124 if card.readblock(x):
125 print card.data[:8],
126 print card.ReadablePrint(card.ToBinary(card.data[:8])),
127 if x > 2:
128 if int(plock[x:x+1]) == 1:
129 print ' locked'
130 else:
131 print ' unlocked'
132 else:
133 print ' -'
134 else:
135 print 'read error: %s' % card.errorcode
136 print
137
138 if x > 0:
139 os._exit(False)
140 else:
141 os._exit(True)
Something went wrong with that request. Please try again.