mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
New outlib library for output-related functions
This commit is contained in:
@@ -3,6 +3,7 @@ local datetime = require "datetime"
|
||||
local formulas = require "formulas"
|
||||
local math = require "math"
|
||||
local nmap = require "nmap"
|
||||
local outlib = require "outlib"
|
||||
local stdnse = require "stdnse"
|
||||
local table = require "table"
|
||||
|
||||
@@ -126,26 +127,6 @@ local function sorted_keys(t)
|
||||
return ret
|
||||
end
|
||||
|
||||
--- Return a table that yields elements sorted by key when iterated over with pairs()
|
||||
-- Should probably put this in a formatting library later.
|
||||
-- Depends on keys() function defined above.
|
||||
--@param t The table whose data should be used
|
||||
--@return out A table that can be passed to pairs() to get sorted results
|
||||
function sorted_by_key(t)
|
||||
local out = {}
|
||||
setmetatable(out, {
|
||||
__pairs = function(_)
|
||||
local order = sorted_keys(t)
|
||||
return coroutine.wrap(function()
|
||||
for i,k in ipairs(order) do
|
||||
coroutine.yield(k, t[k])
|
||||
end
|
||||
end)
|
||||
end
|
||||
})
|
||||
return out
|
||||
end
|
||||
|
||||
postaction = function()
|
||||
local skews = nmap.registry.clock_skews
|
||||
|
||||
@@ -184,7 +165,7 @@ postaction = function()
|
||||
end
|
||||
|
||||
if next(out) then
|
||||
return sorted_by_key(out)
|
||||
return outlib.sorted_by_key(out)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local coroutine = require "coroutine"
|
||||
local math = require "math"
|
||||
local nmap = require "nmap"
|
||||
local outlib = require "outlib"
|
||||
local shortport = require "shortport"
|
||||
local sslcert = require "sslcert"
|
||||
local stdnse = require "stdnse"
|
||||
@@ -1070,26 +1071,6 @@ portrule = function (host, port)
|
||||
return shortport.ssl(host, port) or sslcert.getPrepareTLSWithoutReconnect(port)
|
||||
end
|
||||
|
||||
--- Return a table that yields elements sorted by key when iterated over with pairs()
|
||||
-- Should probably put this in a formatting library later.
|
||||
-- Depends on keys() function defined above.
|
||||
--@param t The table whose data should be used
|
||||
--@return out A table that can be passed to pairs() to get sorted results
|
||||
function sorted_by_key(t)
|
||||
local out = {}
|
||||
setmetatable(out, {
|
||||
__pairs = function(_)
|
||||
local order = sorted_keys(t)
|
||||
return coroutine.wrap(function()
|
||||
for i,k in ipairs(order) do
|
||||
coroutine.yield(k, t[k])
|
||||
end
|
||||
end)
|
||||
end
|
||||
})
|
||||
return out
|
||||
end
|
||||
|
||||
action = function(host, port)
|
||||
|
||||
if not have_ssl then
|
||||
@@ -1129,5 +1110,5 @@ action = function(host, port)
|
||||
end
|
||||
results["least strength"] = least
|
||||
|
||||
return sorted_by_key(results)
|
||||
return outlib.sorted_by_key(results)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user