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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
local bit = require "bit"
local zlib = require "zlib"
local data = '%s-%s'
local mac_data_file = "file_1.txt" local imei_data_file = "file_2.txt"
local function load_data(tb, file_name) local tpl = "%s" for e in io.lines(file_name) do table.insert(tb, tpl.format(e)) end end
local function private_enc(raw, key) local compressed_data = zlib.compress(raw) local compressed_bytes = { string.byte(compressed_data, 1, -1) } local key_bytes = { string.byte(key, 1, -1) }
local encryped_data = {} local key_len = #key_bytes
for i in pairs(compressed_bytes) do local a = bit.bxor(compressed_bytes[i], key_bytes[(i - 1) % key_len + 1]) table.insert(encryped_data, string.char(a)) end
return table.concat(encryped_data, "") end
local mac_table = {} local imei_table = {}
load_data(mac_table, mac_data_file) load_data(imei_table, imei_data_file)
local mac_table_len = #mac_table local imei_table_len = #imei_table
local counter = 1 local all_threads = {}
function setup(thread) thread:set("id", counter) counter = counter + 1 table.insert(all_threads, thread) end
function init(args) ok_count = 0 all_count = 0 end
function request() local mac_idx = math.random(mac_table_len) local imei_idx = math.random(imei_table_len)
local mac = mac_table[mac_idx] local imei = imei_table[imei_idx]
all_count=all_count + 1
local raw_data = string.format(data, mac, imei)
local key = "key" local post_data = private_enc(raw_data, key) local post_data_len = string.len(post_data) local header = { ["Content-Type"] = "application/json", ["Content-Length"] = post_data_len }
return wrk.format("POST", "/r?v=5.2&e=1&c=1", header, post_data) end
function response(status, headers, body) if 200 == status then ok_count = ok_count + 1 end end
function done(summary, latency, requests) local msg = "made %d requests and got %d responses ok" print(msg:format(all_count, ok_count)) end
|