From f3e08e85a0453e7d57a6441fb71e74586657c188 Mon Sep 17 00:00:00 2001 From: djalal Date: Mon, 16 Aug 2010 22:06:49 +0000 Subject: [PATCH] Merge r19753,r19755,r19756,r19776,r19783 changes from nmap-exp/djalal/nmap-add-targets. The changes introduce a new stdnse function 'get_script_args()' to parse script arguments. --- nselib/stdnse.lua | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/nselib/stdnse.lua b/nselib/stdnse.lua index 68691d930..206de583a 100644 --- a/nselib/stdnse.lua +++ b/nselib/stdnse.lua @@ -10,6 +10,8 @@ local pairs = pairs local ipairs = ipairs local tonumber = tonumber; local type = type +local select = select +local unpack = unpack local ceil = math.ceil local max = math.max @@ -561,6 +563,49 @@ function format_output(status, data, indent) return result end +--- Parses the script arguments passed to the --script-args option. +-- +-- @usage +-- --script-args 'script.arg1=value,script.arg3,script-x.arg=value' +-- local arg1, arg2, arg3 = get_script_args('script.arg1','script.arg2','script.arg3') +-- => arg1 = value +-- => arg2 = nil +-- => arg3 = 1 +-- +-- --script-args 'displayall,unsafe,script-x.arg=value,script-y.arg=value' +-- local displayall, unsafe = get_script_args('displayall','unsafe') +-- => displayall = 1 +-- => unsafe = 1 +-- +-- --script-args 'dns-cache-snoop.mode=timed,dns-cache-snoop.domains={host1,host2}' +-- local mode, domains = get_script_args('dns-cache-snoop.mode', +-- 'dns-cache-snoop.domains') +-- => mode = 'timed' +-- => domains = {host1,host2} +-- +-- @param Arguments Script arguments to check. +-- @return Arguments values. +function get_script_args (...) + local args, args_num = {}, select("#", ...) + + for i = 1, args_num do + local option = select(i, ...) + + if nmap.registry.args[option] then + args[i] = nmap.registry.args[option] + else + for _, v in ipairs(nmap.registry.args) do + if v == option then + args[i] = 1 + end + end + end + + end + + return unpack(args, 1, args_num) +end + --- This function allows you to create worker threads that may perform -- network tasks in parallel with your script thread. --