mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-28 23:19:33 +00:00
Added mapServiceName
Example mapServiceName(80, "tcp")
This commit is contained in:
parent
48e0417aa2
commit
38f0047dc1
1 changed files with 49 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue