Skip to content
This repository
tree: e9be4eb5e9
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 74 lines (66 sloc) 2.123 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
#!/usr/bin/python

# writemifare1k.py - write all blocks on a mifare standard tag
#
# Adam Laurie <adam@algroup.co.uk>
# http://rfidiot.org/
#
# This code is copyright (c) Adam Laurie, 2006, All rights reserved.
# For non-commercial use only, the following terms apply - for all other
# uses, please contact the author:
#
# This code is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#


import rfidiot
import sys
import random
import string
import os

try:
        card= rfidiot.card
except:
print "Couldn't open reader!"
        os._exit(True)

args= rfidiot.args
help= rfidiot.help

card.info('writemifare1k v0.1f')
card.select()
print 'Card ID: ' + card.uid
while True:
x= string.upper(raw_input('\n*** Warning! This will overwrite all data blocks! Proceed (y/n)? '))
if x == 'N':
os._exit(False)
if x == 'Y':
break

sector = 1
while sector < 0x10:
        for type in ['AA', 'BB', 'FF']:
                card.select()
print ' sector %02x: Keytype: %s' % (sector, type),
                if card.login(sector,type,'FFFFFFFFFFFF'):
for block in range(3):
                 print '\n block %02x: ' % ((sector * 4) + block),
if len(args) == 1:
data= args[0]
else:
data = '%032x' % random.getrandbits(128)
                         print 'Data: ' + data,
if card.writeblock((sector * 4) + block,data):
print ' OK'
                 elif card.errorcode:
                         print 'error %s %s' % (card.errorcode , card.ISO7816ErrorCodes[card.errorcode])
elif type == 'FF':
print 'login failed'
                print '\r',
                sys.stdout.flush()
        sector += 1
print
print
os._exit(False)
Something went wrong with that request. Please try again.