mirror of
https://github.com/nmap/nmap.git
synced 2025-12-27 01:49:03 +00:00
Include MAC and interface name in targets-ipv6-multicast-* output.
This commit is contained in:
@@ -17,6 +17,7 @@ license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
|
||||
categories = {"discovery","broadcast"}
|
||||
|
||||
require 'nmap'
|
||||
require 'tab'
|
||||
require 'target'
|
||||
require 'packet'
|
||||
local bit = require 'bit'
|
||||
@@ -56,6 +57,17 @@ local function get_interfaces()
|
||||
return interfaces
|
||||
end
|
||||
|
||||
local function format_mac(mac)
|
||||
local octets
|
||||
|
||||
octets = {}
|
||||
for _, v in ipairs({ string.byte(mac, 1, #mac) }) do
|
||||
octets[#octets + 1] = string.format("%02x", v)
|
||||
end
|
||||
|
||||
return stdnse.strjoin(":", octets)
|
||||
end
|
||||
|
||||
local function single_interface_broadcast(if_nfo, results)
|
||||
stdnse.print_debug("Starting " .. SCRIPT_NAME .. " on " .. if_nfo.device)
|
||||
|
||||
@@ -106,7 +118,7 @@ local function single_interface_broadcast(if_nfo, results)
|
||||
local target_str = packet.toipv6(reply.ip6_src)
|
||||
if not results[target_str] then
|
||||
target.add(target_str)
|
||||
results[#results + 1] = target_str
|
||||
results[#results + 1] = { address = target_str, mac = format_mac(reply.mac_src), iface = if_nfo.device }
|
||||
results[target_str] = true
|
||||
end
|
||||
end
|
||||
@@ -119,6 +131,21 @@ local function single_interface_broadcast(if_nfo, results)
|
||||
condvar("signal")
|
||||
end
|
||||
|
||||
local function format_output(results)
|
||||
local output = tab.new()
|
||||
|
||||
for _, record in ipairs(results) do
|
||||
tab.addrow(output, "IP: " .. record.address, "MAC: " .. record.mac, "IFACE: " .. record.iface)
|
||||
end
|
||||
if #results > 0 then
|
||||
output = { tab.dump(output) }
|
||||
if not target.ALLOW_NEW_TARGETS then
|
||||
output[#output + 1] = "Use --script-args=newtargets to add the results as targets"
|
||||
end
|
||||
return stdnse.format_output(true, output)
|
||||
end
|
||||
end
|
||||
|
||||
action = function()
|
||||
local threads = {}
|
||||
local results = {}
|
||||
@@ -137,7 +164,5 @@ action = function()
|
||||
end
|
||||
until next(threads) == nil
|
||||
|
||||
if #results > 0 then
|
||||
return stdnse.format_output(true, results)
|
||||
end
|
||||
return format_output(results)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user