ntopng/scripts/lua/mac_pkt_distro.lua
emanuele-f 9bbeb3a601 Implement device IPv4 vs IPv6 breakdown
Note: the breakdown is only calculated on the realtime hosts traffic

Closes #1155
2018-03-12 13:13:25 +01:00

51 lines
1.1 KiB
Lua

--
-- (C) 2013-17 - 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 = {}
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 isIPv6Address(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,
}
end
if ipv6_packets > 0 then
res[#res + 1] = {
label = i18n("ipv6"),
value = ipv6_packets,
}
end
end
end
print(json.encode(res))