mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-30 16:09:32 +00:00
61 lines
1.3 KiB
Lua
61 lines
1.3 KiB
Lua
--
|
|
-- (C) 2013-24 - ntop.org
|
|
--
|
|
|
|
local dirs = ntop.getDirs()
|
|
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
|
|
|
require "lua_utils"
|
|
local json = require("dkjson")
|
|
|
|
sendHTTPContentTypeHeader('text/html')
|
|
interface.select(ifname)
|
|
|
|
local mac = _GET["mac"]
|
|
local distr = _GET["distr"]
|
|
local res = {}
|
|
local found = false
|
|
|
|
if distr == "ipver" then
|
|
local mac_hosts = interface.getHostsInfo(true --[[ no details ]], nil, nil, toSkip, nil, nil, nil, nil, nil, nil, mac)
|
|
|
|
if mac_hosts ~= nil and mac_hosts.hosts ~= nil then
|
|
local ipv4_packets = 0
|
|
local ipv6_packets = 0
|
|
|
|
for _, host in pairs(mac_hosts.hosts) do
|
|
local host_packets = host["packets.sent"] + host["packets.rcvd"]
|
|
|
|
if isIPv6(host.ip) then
|
|
ipv6_packets = ipv6_packets + host_packets
|
|
else
|
|
ipv4_packets = ipv4_packets + host_packets
|
|
end
|
|
end
|
|
|
|
if ipv4_packets > 0 then
|
|
res[#res + 1] = {
|
|
label = i18n("ipv4"),
|
|
value = ipv4_packets,
|
|
}
|
|
found = true
|
|
end
|
|
|
|
if ipv6_packets > 0 then
|
|
res[#res + 1] = {
|
|
label = i18n("ipv6"),
|
|
value = ipv6_packets,
|
|
}
|
|
found = true
|
|
end
|
|
end
|
|
end
|
|
|
|
if(not(found)) then
|
|
res[#res + 1] = {
|
|
label = "No IP",
|
|
value = 1,
|
|
}
|
|
end
|
|
|
|
print(json.encode(res))
|