mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Move comma-separated list code to outlib
This commit is contained in:
@@ -17,6 +17,7 @@ local yield = coroutine.yield
|
|||||||
|
|
||||||
local table = require "table"
|
local table = require "table"
|
||||||
local sort = table.sort
|
local sort = table.sort
|
||||||
|
local concat = table.concat
|
||||||
|
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
local ipairs = ipairs
|
local ipairs = ipairs
|
||||||
@@ -46,4 +47,32 @@ function sorted_by_key(t)
|
|||||||
return out
|
return out
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local commasep = {
|
||||||
|
__tostring = function (t)
|
||||||
|
return concat(t, ", ")
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
--- Comma-separated list output
|
||||||
|
--
|
||||||
|
-- This adds a <code>__tostring</code> metamethod to a list (integer-indexed
|
||||||
|
-- table) so that it will be formatted as a comma-separated list when converted
|
||||||
|
-- to a string.
|
||||||
|
-- @param t The table to format
|
||||||
|
-- @param sep (Optional) list separator character, default: ", "
|
||||||
|
function list_sep(t, sep)
|
||||||
|
-- Reuse closures and metatables as much as possible
|
||||||
|
local oldmt = getmetatable(t)
|
||||||
|
local newmt = sep and {
|
||||||
|
__tostring = function(tt)
|
||||||
|
return concat(tt, sep)
|
||||||
|
end} or commasep
|
||||||
|
-- Avoid clobbering old metatable or our static commasep table
|
||||||
|
if oldmt and oldmt ~= commasep then
|
||||||
|
oldmt.__tostring = newmt.__tostring
|
||||||
|
else
|
||||||
|
setmetatable(t, newmt)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return _ENV
|
return _ENV
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local afp = require "afp"
|
local afp = require "afp"
|
||||||
local nmap = require "nmap"
|
local nmap = require "nmap"
|
||||||
|
local outlib = require "outlib"
|
||||||
local shortport = require "shortport"
|
local shortport = require "shortport"
|
||||||
local stdnse = require "stdnse"
|
local stdnse = require "stdnse"
|
||||||
local table = require "table"
|
local table = require "table"
|
||||||
@@ -88,12 +89,6 @@ categories = {"default", "discovery", "safe"}
|
|||||||
|
|
||||||
portrule = shortport.port_or_service(548, "afp")
|
portrule = shortport.port_or_service(548, "afp")
|
||||||
|
|
||||||
local commasep = {
|
|
||||||
__tostring = function (t)
|
|
||||||
return table.concat(t, ", ")
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
action = function(host, port)
|
action = function(host, port)
|
||||||
|
|
||||||
local socket = nmap.new_socket()
|
local socket = nmap.new_socket()
|
||||||
@@ -148,11 +143,11 @@ action = function(host, port)
|
|||||||
|
|
||||||
-- list the supported AFP versions
|
-- list the supported AFP versions
|
||||||
result["AFP Versions"] = response.afp_versions
|
result["AFP Versions"] = response.afp_versions
|
||||||
setmetatable(result["AFP Versions"], commasep)
|
outlib.list_sep(result["AFP Versions"])
|
||||||
|
|
||||||
-- list the supported UAMs (User Authentication Modules)
|
-- list the supported UAMs (User Authentication Modules)
|
||||||
result["UAMs"] = response.uams
|
result["UAMs"] = response.uams
|
||||||
setmetatable(result["UAMs"], commasep)
|
outlib.list_sep(result["UAMs"])
|
||||||
|
|
||||||
-- server signature, not sure of the format here so just showing a hex string
|
-- server signature, not sure of the format here so just showing a hex string
|
||||||
if response.flags.ServerSignature then
|
if response.flags.ServerSignature then
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ local dhcp = require "dhcp"
|
|||||||
local ipOps = require "ipOps"
|
local ipOps = require "ipOps"
|
||||||
local math = require "math"
|
local math = require "math"
|
||||||
local nmap = require "nmap"
|
local nmap = require "nmap"
|
||||||
|
local outlib = require "outlib"
|
||||||
local packet = require "packet"
|
local packet = require "packet"
|
||||||
|
local rand = require "rand"
|
||||||
local stdnse = require "stdnse"
|
local stdnse = require "stdnse"
|
||||||
local string = require "string"
|
local string = require "string"
|
||||||
local table = require "table"
|
local table = require "table"
|
||||||
@@ -141,12 +143,6 @@ local function dhcp_listener(sock, timeout, xid, result)
|
|||||||
condvar "signal"
|
condvar "signal"
|
||||||
end
|
end
|
||||||
|
|
||||||
local commasep = {
|
|
||||||
__tostring = function (t)
|
|
||||||
return table.concat(t, ", ")
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
local function fail (err) return stdnse.format_output(false, err) end
|
local function fail (err) return stdnse.format_output(false, err) end
|
||||||
|
|
||||||
action = function()
|
action = function()
|
||||||
@@ -230,7 +226,7 @@ action = function()
|
|||||||
result_table["IP Offered"] = r.yiaddr_str
|
result_table["IP Offered"] = r.yiaddr_str
|
||||||
for _, v in ipairs(r.options) do
|
for _, v in ipairs(r.options) do
|
||||||
if(type(v.value) == 'table') then
|
if(type(v.value) == 'table') then
|
||||||
setmetatable(v.value, commasep)
|
outlib.list_sep(v.value)
|
||||||
end
|
end
|
||||||
result_table[ v.name ] = v.value
|
result_table[ v.name ] = v.value
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
local dhcp = require "dhcp"
|
local dhcp = require "dhcp"
|
||||||
local rand = require "rand"
|
local rand = require "rand"
|
||||||
local nmap = require "nmap"
|
local nmap = require "nmap"
|
||||||
|
local outlib = require "outlib"
|
||||||
local shortport = require "shortport"
|
local shortport = require "shortport"
|
||||||
local stdnse = require "stdnse"
|
local stdnse = require "stdnse"
|
||||||
local string = require "string"
|
local string = require "string"
|
||||||
@@ -103,12 +104,6 @@ function portrule(host, port)
|
|||||||
return shortport.portnumber(67, "udp")(host, port)
|
return shortport.portnumber(67, "udp")(host, port)
|
||||||
end
|
end
|
||||||
|
|
||||||
local commasep = {
|
|
||||||
__tostring = function (t)
|
|
||||||
return table.concat(t, ", ")
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
action = function(host, port)
|
action = function(host, port)
|
||||||
local dhcptype = (stdnse.get_script_args(SCRIPT_NAME .. ".dhcptype") or "DHCPINFORM"):upper()
|
local dhcptype = (stdnse.get_script_args(SCRIPT_NAME .. ".dhcptype") or "DHCPINFORM"):upper()
|
||||||
local dhcptypeid = dhcp.request_types[dhcptype]
|
local dhcptypeid = dhcp.request_types[dhcptype]
|
||||||
@@ -185,7 +180,7 @@ action = function(host, port)
|
|||||||
end
|
end
|
||||||
for _, v in ipairs(result.options) do
|
for _, v in ipairs(result.options) do
|
||||||
if type(v.value) == 'table' then
|
if type(v.value) == 'table' then
|
||||||
setmetatable(v.value, commasep)
|
outlib.list_sep(v.value)
|
||||||
end
|
end
|
||||||
result_table[ v.name ] = v.value
|
result_table[ v.name ] = v.value
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
local dns = require "dns"
|
local dns = require "dns"
|
||||||
local ipOps = require "ipOps"
|
local ipOps = require "ipOps"
|
||||||
local nmap = require "nmap"
|
local nmap = require "nmap"
|
||||||
|
local outlib = require "outlib"
|
||||||
local packet = require "packet"
|
local packet = require "packet"
|
||||||
local stdnse = require "stdnse"
|
local stdnse = require "stdnse"
|
||||||
local string = require "string"
|
local string = require "string"
|
||||||
@@ -152,12 +153,6 @@ local function stringify_noop(flags, data)
|
|||||||
return "replied"
|
return "replied"
|
||||||
end
|
end
|
||||||
|
|
||||||
local commasep = {
|
|
||||||
__tostring = function (t)
|
|
||||||
return table.concat(t, ", ")
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
-- RFC 4620, section 6.3.
|
-- RFC 4620, section 6.3.
|
||||||
local function stringify_nodename(flags, data)
|
local function stringify_nodename(flags, data)
|
||||||
local status, names
|
local status, names
|
||||||
@@ -170,7 +165,7 @@ local function stringify_nodename(flags, data)
|
|||||||
names[#names+1] = "(parsing error)"
|
names[#names+1] = "(parsing error)"
|
||||||
end
|
end
|
||||||
|
|
||||||
setmetatable(names, commasep)
|
outlib.list_sep(names)
|
||||||
return names
|
return names
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -195,7 +190,7 @@ local function stringify_nodeaddresses(flags, data)
|
|||||||
addrs[#addrs+1] = "(more omitted for space reasons)"
|
addrs[#addrs+1] = "(more omitted for space reasons)"
|
||||||
end
|
end
|
||||||
|
|
||||||
setmetatable(addrs, commasep)
|
outlib.list_sep(addrs)
|
||||||
return addrs
|
return addrs
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -217,7 +212,7 @@ local function stringify_nodeipv4addresses(flags, data)
|
|||||||
-- Check for DNS names.
|
-- Check for DNS names.
|
||||||
status, names = try_decode_nodenames(data .. "\0\0")
|
status, names = try_decode_nodenames(data .. "\0\0")
|
||||||
if status then
|
if status then
|
||||||
setmetatable(names, commasep)
|
outlib.list_sep(names)
|
||||||
return names
|
return names
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -237,7 +232,7 @@ local function stringify_nodeipv4addresses(flags, data)
|
|||||||
addrs[#addrs+1] = "(more omitted for space reasons)"
|
addrs[#addrs+1] = "(more omitted for space reasons)"
|
||||||
end
|
end
|
||||||
|
|
||||||
setmetatable(addrs, commasep)
|
outlib.list_sep(addrs)
|
||||||
return addrs
|
return addrs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local ipOps = require "ipOps"
|
local ipOps = require "ipOps"
|
||||||
local nmap = require "nmap"
|
local nmap = require "nmap"
|
||||||
|
local outlib = require "outlib"
|
||||||
local stdnse = require "stdnse"
|
local stdnse = require "stdnse"
|
||||||
local table = require "table"
|
local table = require "table"
|
||||||
local tableaux = require "tableaux"
|
local tableaux = require "tableaux"
|
||||||
@@ -85,12 +86,6 @@ hostaction = function(host)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local commasep = {
|
|
||||||
__tostring = function (t)
|
|
||||||
return table.concat(t, ", ")
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
postaction = function()
|
postaction = function()
|
||||||
local db = nmap.registry[SCRIPT_NAME]
|
local db = nmap.registry[SCRIPT_NAME]
|
||||||
if ( db == nil ) then
|
if ( db == nil ) then
|
||||||
@@ -108,7 +103,7 @@ postaction = function()
|
|||||||
local result_entries = ports[port]
|
local result_entries = ports[port]
|
||||||
ipOps.ip_sort(result_entries)
|
ipOps.ip_sort(result_entries)
|
||||||
if mode == 'horizontal' then
|
if mode == 'horizontal' then
|
||||||
setmetatable(result_entries, commasep)
|
outlib.list_sep(result_entries)
|
||||||
end
|
end
|
||||||
results[("%s/%s"):format(port, proto)] = result_entries
|
results[("%s/%s"):format(port, proto)] = result_entries
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user