mirror of
https://github.com/nmap/nmap.git
synced 2025-12-08 05:31:31 +00:00
Added a function that generates random strings to stdnse.lua.
This commit is contained in:
@@ -135,6 +135,30 @@ function strsplit(pattern, text)
|
||||
return list;
|
||||
end
|
||||
|
||||
--- Generate a random string.
|
||||
-- You can either provide your own charset or the function will use
|
||||
-- a default one which is [A-Z].
|
||||
-- @param len Length of the string we want to generate.
|
||||
-- @param charset Charset that will be used to generate the string.
|
||||
-- @return A random string of length <code>len</code> consisting of
|
||||
-- characters from <code>charset</code> if one was provided, otherwise
|
||||
-- <code>charset</code> defaults to [A-Z] letters.
|
||||
function generate_random_string(len, charset)
|
||||
local t = {}
|
||||
local ascii_A = 65
|
||||
local ascii_Z = 90
|
||||
if charset then
|
||||
for i=1,len do
|
||||
t[i]=charset[math.random(#charset)]
|
||||
end
|
||||
else
|
||||
for i=1,len do
|
||||
t[i]=string.char(math.random(ascii_A,ascii_Z))
|
||||
end
|
||||
end
|
||||
return table.concat(t)
|
||||
end
|
||||
|
||||
--- Return a wrapper closure around a socket that buffers socket reads into
|
||||
-- chunks separated by a pattern.
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user