1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-25 00:49:01 +00:00

New function stdnse.format_mac

This function will format a MAC address as colon-separated hex bytes.
It's really very simple: stdnse.tohex(mac, {separator=":"})

This commit updates all the instances I could find of the varying
convoluted attempts at performing this conversion.
This commit is contained in:
dmiller
2014-01-16 21:50:30 +00:00
parent a6b79f9976
commit 197f28265f
13 changed files with 21 additions and 83 deletions

View File

@@ -60,17 +60,6 @@ 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)
@@ -129,7 +118,7 @@ local function single_interface_broadcast(if_nfo, results)
if target.ALLOW_NEW_TARGETS then
target.add(target_str)
end
results[#results + 1] = { address = target_str, mac = format_mac(reply.mac_src), iface = if_nfo.device }
results[#results + 1] = { address = target_str, mac = stdnse.format_mac(reply.mac_src), iface = if_nfo.device }
results[target_str] = true
end
end