text
[RRG-proxmark3.git] / client / luascripts / lf_ioprox_bulkclone.lua
blob46e33c63a4380e45eb986605252d9a2269a94883
1 local getopt = require('getopt')
2 local cmds = require('commands')
5 copyright = ''
6 author = "TheChamp669"
7 version = 'v1.0.0'
8 desc = [[
9 Perform bulk enrollment of 26 bit IO Prox / Kantech style RFID Tags
10 The vnc is set to 2.
11 For more info, check the comments in the code
13 example = [[
15 script run lf_ioprox_bulkclone.lua -f 1 -b 1000
17 usage = [[
18 script run lf_ioprox_bulkclone.lua -f facility -b base_id_num
20 arguments = [[
21 -h : this help
22 -f : facility id
23 -b : starting card id
25 local DEBUG = true
27 ---
28 -- A debug printout-function
29 local function dbg(args)
30 if not DEBUG then return end
31 if type(args) == 'table' then
32 local i = 1
33 while args[i] do
34 dbg(args[i])
35 i = i+1
36 end
37 else
38 print('###', args)
39 end
40 end
41 ---
42 -- This is only meant to be used when errors occur
43 local function oops(err)
44 print('ERROR:', err)
45 core.clearCommandBuffer()
46 return nil, errr
47 end
48 ---
49 -- Usage help
50 local function help()
51 print(copyright)
52 print(author)
53 print(version)
54 print(desc)
55 print(ansicolors.cyan..'Usage'..ansicolors.reset)
56 print(usage)
57 print(ansicolors.cyan..'Arguments'..ansicolors.reset)
58 print(arguments)
59 print(ansicolors.cyan..'Example usage'..ansicolors.reset)
60 print(example)
61 end
62 ---
63 -- Exit message
64 local function exitMsg(msg)
65 print( string.rep('--',20) )
66 print( string.rep('--',20) )
67 print(msg)
68 print()
69 end
71 local function main(args)
73 print( string.rep('--',20) )
74 print( string.rep('--',20) )
75 print()
77 if #args == 0 then return help() end
79 for o, a in getopt.getopt(args, 'f:b:h') do
80 if o == 'h' then return help() end
81 if o == 'f' then
82 if isempty(a) then
83 print('You did not supply a facility code, using 0')
84 fc = 0
85 else
86 fc = a
87 end
88 end
89 if o == 'b' then
90 if isempty(a) then return oops('You must supply the flag -b (starting card number)') end
91 cn = a
92 end
93 end
95 local successful_writes = {}
96 local timestamp = os.date('%Y-%m-%d %H:%M:%S', os.time())
98 while true do
99 print(string.format("Setting fob to Facility Code: %d, Card Number: %d", fc, cn))
101 -- Writing to block 0 with the specific data for ioProx card format
102 core.console("lf t55xx write -b 0 -d 00147040")
104 -- Command to set facility code and card number on the fob
105 local command = string.format("lf io clone --vn 2 --fc %d --cn %d", fc, cn)
106 core.console(command)
108 table.insert(successful_writes, string.format("%d,%d", fc, cn))
109 print("Fob created successfully.")
111 print("Press Enter to create the next fob, type 'r' and press Enter to retry, or type 'q' and press Enter to quit.")
112 local user_input = io.read()
114 if user_input:lower() == 'q' then
115 print("Timestamp: ", timestamp)
116 print("Successful Writes:")
117 for _, v in ipairs(successful_writes) do print(v) end
118 break
119 elseif user_input:lower() ~= 'r' then
120 cn = cn + 1
125 main(args)