1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-09 22:21:29 +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

@@ -164,20 +164,12 @@ end
local function processMAC(tab)
local function format_mac(mac)
local 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 mac
local mac_table = {}
for host in pairs(tab) do
if ( host.mac_addr ) then
mac = format_mac(host.mac_addr)
mac = stdnse.format_mac(host.mac_addr)
mac_table[mac] = mac_table[mac] or {}
if ( not(contains(mac_table[mac], host.ip)) ) then
table.insert(mac_table[mac], host.ip)