Added mapServiceName

Example mapServiceName(80, "tcp")
This commit is contained in:
Luca Deri 2023-09-18 11:19:19 +02:00
parent 48e0417aa2
commit 38f0047dc1

View file

@ -1404,6 +1404,55 @@ function get_confidence(confidence_id, shorten_string)
return confidence_name
end
-- ##############################################
local services = nil
local function readServices()
if(services == nil) then
local file = io.open("/etc/services", "r")
if not file then return services end
services = {}
for line in file:lines() do
if((line ~= "") and (not(string.starts(line, "#")))) then
line = line:gsub("\t", " ")
line = line:gsub(" ", " ")
local elems = split(line, " ")
local label = elems[1]
local value
local i = 2
while(elems[i] ~= nil) do
if(elems[i] ~= "") then
value = elems[i]
break
end
i = i + 1
end
services[value] = label
-- print(label.." = "..value.."<br>\n")
end
end
file:close()
end
return(services)
end
-- Example mapServiceName(80, "tcp")
function mapServiceName(port, protocol)
readServices()
local key = tostring(port).."/"..protocol
return(services[key])
end
-- ##############################################
if (trace_script_duration ~= nil) then