1
0
mirror of https://github.com/nmap/nmap.git synced 2026-02-02 03:29:02 +00:00

Add xml output to resolveall, improve warnings

This commit is contained in:
dmiller
2016-05-25 20:14:13 +00:00
parent c7852c6ec0
commit 0896c64bae

View File

@@ -26,6 +26,16 @@ record) returned for each host name.
-- | 74.125.39.105
-- | 74.125.39.104
-- |_ Successfully added 6 new targets
-- @xmloutput
-- <elem key="newtargets">4</elem>
-- <table key="hosts">
-- <table key="google.com">
-- <elem>74.125.39.106</elem>
-- <elem>74.125.39.147</elem>
-- <elem>74.125.39.99</elem>
-- <elem>74.125.39.103</elem>
-- </table>
-- </table>
author = "Kris Katterjohn"
@@ -36,7 +46,7 @@ categories = {"safe", "discovery"}
prerule = function()
if not stdnse.get_script_args("resolveall.hosts") then
stdnse.debug3("Skipping '%s' %s, 'resolveall.hosts' argument is missing.", SCRIPT_NAME, SCRIPT_TYPE)
stdnse.verbose1("Skipping '%s', missing required argument 'resolveall.hosts'.", SCRIPT_NAME)
return false
end
return true
@@ -50,7 +60,7 @@ local addtargets = function(list)
if st then
sum = sum + 1
else
stdnse.debug1("Couldn't add target " .. t .. ": " .. err)
stdnse.debug1("Couldn't add target %s: %s", t, err)
end
end
@@ -64,25 +74,29 @@ action = function()
hosts = {hosts}
end
local sum, output = 0, {}
local sum = 0
local output = {}
local xmloutput = {}
for _, host in ipairs(hosts) do
local status, list = nmap.resolve(host, nmap.address_family())
if status and #list > 0 then
if target.ALLOW_NEW_TARGETS then
sum = sum + addtargets(list)
end
table.insert(output,
string.format("Host '%s' resolves to:", host))
xmloutput[host] = list
table.insert(output, string.format("Host '%s' resolves to:", host))
table.insert(output, list)
end
end
xmloutput = {
hosts = xmloutput,
newtargets = sum or 0,
}
if sum > 0 then
table.insert(output,
string.format("Successfully added %d new targets",
tostring(sum)))
table.insert(output, string.format("Successfully added %d new targets", sum))
else
table.insert(output, "Use the 'newtargets' script-arg to add the results as targets")
end
return stdnse.format_output(true, output)
return xmloutput, stdnse.format_output(true, output)
end