1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
--
-- (C) 2013-16 - ntop.org
--
dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
sendHTTPHeader('application/json')
max_num_to_find = 5
print [[
{
"interface" : "]] print(ifname) print [[",
"results": [
]]
query = _GET["query"]
if(query == nil) then query = "" end
num = 0
interface.select(ifname)
if(true) then
res = interface.findHost(query)
for k, v in pairs(res) do
if(v ~= "") then
if(num > 0) then print(",\n") end
print('\t"'..v..'"')
num = num + 1
end
end
else
hosts_stats,total = aggregateHostsStats(interface.getHostsInfo())
-- query = "192"
if(query ~= nil) then
query = string.lower(query)
for _key, value in pairs(hosts_stats) do
if(num >= max_num_to_find) then
break
end
found = 0
if((hosts_stats[_key]["name"] == nil) and (hosts_stats[_key]["ip"] ~= nil)) then
hosts_stats[_key]["name"] = ntop.getResolvedAddress(hosts_stats[_key]["ip"])
end
what = hosts_stats[_key]["name"]
if((what ~= nil) and (string.contains(string.lower(what), query))) then
found = 1
else
what = hosts_stats[_key]["mac"]
if(starts(what, query)) then
found = 1
else
if(hosts_stats[_key]["ip"] ~= nil) then
what = hosts_stats[_key]["ip"]
if(starts(what, query)) then
found = 1
end
end
end
end
if(found == 1) then
if(num > 0) then print(",\n") end
print("\t\""..what .. "\"")
num = num + 1
end
end
end
end
print [[
]
}
]]
|