style
[RRG-proxmark3.git] / client / luascripts / lf_awid_bulkclone.lua
blob0085a09c9e8305f48b6be00049b12414ebe24abb
1 local getopt = require('getopt')
4 copyright = ''
5 author = "TheChamp669"
6 version = 'v1.0.0'
7 desc = [[
8 Perform bulk enrollment of 26 bit AWID style RFID Tags
9 For more info, check the comments in the code
11 example = [[
13 script run lf_awid_bulkclone.lua -f 1 -b 1000
15 usage = [[
16 script run lf_awid_bulkclone.lua -f facility -b base_id_num
18 arguments = [[
19 -h : this help
20 -f : facility id
21 -b : starting card id
23 local DEBUG = true
24 ---
25 -- A debug printout-function
26 local function dbg(args)
27 if not DEBUG then return end
28 if type(args) == 'table' then
29 local i = 1
30 while args[i] do
31 dbg(args[i])
32 i = i+1
33 end
34 else
35 print('###', args)
36 end
37 end
38 ---
39 -- This is only meant to be used when errors occur
40 local function oops(err)
41 print('ERROR:', err)
42 core.clearCommandBuffer()
43 return nil, errr
44 end
45 ---
46 -- Usage help
47 local function help()
48 print(copyright)
49 print(author)
50 print(version)
51 print(desc)
52 print(ansicolors.cyan..'Usage'..ansicolors.reset)
53 print(usage)
54 print(ansicolors.cyan..'Arguments'..ansicolors.reset)
55 print(arguments)
56 print(ansicolors.cyan..'Example usage'..ansicolors.reset)
57 print(example)
58 end
59 ---
60 -- Exit message
61 local function exitMsg(msg)
62 print( string.rep('--',20) )
63 print( string.rep('--',20) )
64 print(msg)
65 print()
66 end
68 local function showHelp()
69 print("Usage: script run <scriptname> [-h]")
70 print("Options:")
71 print("-h \t This help")
72 end
74 local function main(args)
77 print( string.rep('--',20) )
78 print( string.rep('--',20) )
79 print()
81 if #args == 0 then return help() end
83 for o, a in getopt.getopt(args, 'f:b:c:h') do
84 if o == 'h' then return help() end
85 if o == 'f' then
86 if isempty(a) then
87 print('You did not supply a facility code, using 255')
88 fc = 255
89 else
90 fc = a
91 end
92 end
93 if o == 'b' then
94 if isempty(a) then
95 print('You did not supply a starting card number, using 59615')
96 cn = 59615
97 else
98 cn = a
99 end
103 -- Example starting values
104 local sessionStart = os.date("%Y_%m_%d_%H_%M_%S") -- Capture the session start time
106 print("Session Start: " .. sessionStart)
107 print("Facility Code,Card Number")
109 while true do
110 print(string.format("Preparing to Write: Facility Code %d, Card Number %d", fc, cn))
112 local command = string.format("lf awid clone --fmt 26 --fc %d --cn %d", fc, cn)
113 core.console(command)
115 print(string.format("%d,%d", fc, cn))
117 print("Press Enter to continue with the next card number or type 'q' and press Enter to quit.")
118 local user_input = io.read()
120 if user_input:lower() == 'q' then
121 break
122 else
123 cn = cn + 1
128 main(args)