diff --git a/scripts/broadcast-dhcp-discover.nse b/scripts/broadcast-dhcp-discover.nse
index 05369559d..cf74e5b13 100644
--- a/scripts/broadcast-dhcp-discover.nse
+++ b/scripts/broadcast-dhcp-discover.nse
@@ -37,6 +37,16 @@ The script needs to be run as a privileged user, typically root.
-- | Domain Name Server: 192.168.1.1
-- |_ Domain Name: localdomain
--
+-- @xmloutput
+-- 192.168.1.114
+-- DHCPOFFER
+-- 192.168.1.1
+-- 1 day, 0:00:00
+-- 255.255.255.0
+-- 192.168.1.1
+-- 192.168.1.1
+-- localdomain
+--
-- @args broadcast-dhcp-discover.timeout time in seconds to wait for a response
-- (default: 10s)
--
@@ -133,6 +143,11 @@ local function dhcp_listener(sock, timeout, xid, result)
condvar "signal"
end
+local commasep = {
+ __tostring = function (t)
+ return table.concat(t, ", ")
+ end
+}
action = function()
@@ -197,17 +212,21 @@ action = function()
end
until next(threads) == nil
- local response = {}
+ local response = stdnse.output_table()
-- Display the results
for i, r in ipairs(result) do
- table.insert(response, string.format("IP Offered: %s", r.yiaddr_str))
+ local result_table = stdnse.output_table()
+
+ result_table["IP Offered"] = r.yiaddr_str
for _, v in ipairs(r.options) do
- if(type(v['value']) == 'table') then
- table.insert(response, string.format("%s: %s", v['name'], stdnse.strjoin(", ", v['value'])))
- else
- table.insert(response, string.format("%s: %s\n", v['name'], v['value']))
+ if(type(v.value) == 'table') then
+ setmetatable(v.value, commasep)
end
+ result_table[ v.name ] = v.value
end
+
+ response[string.format("Response %d of %d", i, #result)] = result_table
end
- return stdnse.format_output(true, response)
+
+ return response
end
diff --git a/scripts/dhcp-discover.nse b/scripts/dhcp-discover.nse
index dc9478ad8..057c74175 100644
--- a/scripts/dhcp-discover.nse
+++ b/scripts/dhcp-discover.nse
@@ -45,13 +45,24 @@ Some of the more useful fields:
-- Interesting ports on 192.168.1.1:
-- PORT STATE SERVICE
-- 67/udp open dhcps
--- | dhcp-discover:
--- | | DHCP Message Type: DHCPACK
--- | | Server Identifier: 192.168.1.1
--- | | IP Address Lease Time: 1 day, 0:00:00
--- | | Subnet Mask: 255.255.255.0
--- | | Router: 192.168.1.1
--- |_ |_ Domain Name Server: 208.81.7.10, 208.81.7.14
+-- | dhcp-discover:
+-- | DHCP Message Type: DHCPACK
+-- | Server Identifier: 192.168.1.1
+-- | IP Address Lease Time: 1 day, 0:00:00
+-- | Subnet Mask: 255.255.255.0
+-- | Router: 192.168.1.1
+-- |_ Domain Name Server: 208.81.7.10, 208.81.7.14
+--
+-- @xmloutput
+-- DHCPACK
+-- 192.168.1.1
+-- 1 day, 0:00:00
+-- 255.255.255.0
+-- 192.168.1.1
+--
+-- 208.81.7.10
+-- 208.81.7.14
+--
--
--
@@ -121,6 +132,12 @@ local function go(host, port)
return true, results
end
+local commasep = {
+ __tostring = function (t)
+ return table.concat(t, ", ")
+ end
+}
+
action = function(host, port)
local status, results = go(host, port)
@@ -138,35 +155,29 @@ action = function(host, port)
nmap.set_port_state(host, port, "open")
end
- local response = {}
+ local response = stdnse.output_table()
-- Display the results
for i, result in ipairs(results) do
- local result_table = {}
+ local result_table = stdnse.output_table()
if ( nmap.registry.args.dhcptype and
"DHCPINFORM" ~= nmap.registry.args.dhcptype ) then
- table.insert(result_table, string.format("IP Offered: %s", result.yiaddr_str))
+ result_table["IP Offered"] = result.yiaddr_str
end
for _, v in ipairs(result.options) do
- if(type(v['value']) == 'table') then
- table.insert(result_table, string.format("%s: %s", v['name'], stdnse.strjoin(", ", v['value'])))
- else
- table.insert(result_table, string.format("%s: %s\n", v['name'], v['value']))
+ if(type(v.value) == 'table') then
+ setmetatable(v.value, commasep)
end
+ result_table[ v.name ] = v.value
end
if(#results == 1) then
response = result_table
else
- result_table['name'] = string.format("Result %d of %d", i, #results)
- table.insert(response, result_table)
+ response[string.format("Response %d of %d", i, #results)] = result_table
end
end
- return stdnse.format_output(true, response)
+ return response
end
-
-
-
-