mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-30 07:59:35 +00:00
Implemented vs_utils.get_active_hosts
This commit is contained in:
parent
9dd0507025
commit
09db773f07
1 changed files with 20 additions and 24 deletions
|
|
@ -371,36 +371,32 @@ end
|
|||
|
||||
-- **********************************************************
|
||||
|
||||
-- Process to retrieve list of ports using nmap
|
||||
function vs_utils.get_ports(host)
|
||||
-- FIXME
|
||||
-- must returns array of object {key: port_id}
|
||||
-- Example vs_utils.get_active_hosts("192.168.2.0", "24")
|
||||
function vs_utils.get_active_hosts(host, cidr)
|
||||
local result = {}
|
||||
|
||||
result[#result+1] = {
|
||||
key = 22
|
||||
}
|
||||
cidr = tonumber(cidr)
|
||||
|
||||
if((cidr == 32) or (cidr == 128) or (host:find('.') == nil)) then
|
||||
result[#result+1] = host -- return it as is
|
||||
else
|
||||
local s = string.split(host, '%.')
|
||||
local net = s[1].."."..s[2].."."..s[3].."."
|
||||
local command = 'nmap -sP -n ' .. net .. '1-254 | grep "Nmap scan report for" | cut -d " " -f 5'
|
||||
local handle = io.popen(command)
|
||||
local out = handle:read("*a")
|
||||
local l = lines(out)
|
||||
|
||||
handle:close()
|
||||
|
||||
for _,h in pairs(l) do
|
||||
result[#result+1] = h
|
||||
end
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
-- **********************************************************
|
||||
|
||||
function vs_utils.get_active_hosts(host, cidr)
|
||||
|
||||
local result = {}
|
||||
|
||||
for i in range(1, 2 --[[ instead of cidr just for example --]], 1) do
|
||||
|
||||
-- FIX ME
|
||||
host = host:sub(1, -2)
|
||||
host = host .. i
|
||||
result[#result+1] = host
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
-- **********************************************************
|
||||
|
||||
return vs_utils
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue