1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-04 05:39:01 +00:00

Move caching code to datafiles lib

Scripts no longer need to implement caching of datafiles tables in the
registry, since the datafiles.lua library keeps its own cache in the
registry. A side-effect is that scripts should not change the tables
returned by datafiles.parse_{protocols,rpc,services,mac_prefixes}(), as
doing so will affect all other scripts that use those functions.
This commit is contained in:
dmiller
2012-07-27 20:07:38 +00:00
parent 959d9a67d3
commit b868e7f3ce
6 changed files with 61 additions and 74 deletions

View File

@@ -184,18 +184,13 @@ end
function get_mac_addr( mac )
local catch = function() return end
local try = nmap.new_try(catch)
-- Build the MAC prefix lookup table
if not nmap.registry.snmp_interfaces then
-- Create the table in the registry so we can share between script instances
nmap.registry.snmp_interfaces = {}
nmap.registry.snmp_interfaces.mac_prefixes = try(datafiles.parse_mac_prefixes())
end
local mac_prefixes = try(datafiles.parse_mac_prefixes())
if mac:len() ~= 6 then
return "Unknown"
else
local prefix = string.upper(string.format("%02x%02x%02x", mac:byte(1), mac:byte(2), mac:byte(3)))
local manuf = nmap.registry.snmp_interfaces.mac_prefixes[prefix] or "Unknown"
local manuf = mac_prefixes[prefix] or "Unknown"
return string.format("%02x:%02x:%02x:%02x:%02x:%02x (%s)", mac:byte(1), mac:byte(2), mac:byte(3), mac:byte(4), mac:byte(5), mac:byte(6), manuf )
end
end