-- -- (C) 2013-15 - ntop.org -- dirs = ntop.getDirs() package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path require "lua_utils" sendHTTPHeader('text/html; charset=iso-8859-1') ntop.dumpFile(dirs.installdir .. "/httpdocs/inc/header.inc") active_page = "hosts" dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua") function getTraffic(stats, host_a, host_b) sent_total = 0 rcvd_total = 0 --io.write(">>> "..host_a.." / "..host_b.."\n") for key, value in pairs(stats) do client = hostinfo2hostkey(flows_stats[key],"cli") server = hostinfo2hostkey(flows_stats[key],"srv") -- io.write(">>> "..flows_stats[key]["cli.ip"].." / "..flows_stats[key]["srv.ip"].."\n") if((client == host_a) and (server == host_b)) then sent_total = sent_total + flows_stats[key]["cli2srv.bytes"] rcvd_total = rcvd_total + flows_stats[key]["srv2cli.bytes"] else if((server == host_a) and (client == host_b)) then sent_total = sent_total + flows_stats[key]["srv2cli.bytes"] rcvd_total = rcvd_total + flows_stats[key]["cli2srv.bytes"] end end end rc = { sent_total, rcvd_total } return(rc) end interface.select(ifname) hosts_stats = interface.getHostsInfo() flows_stats = interface.getFlowsInfo() localhosts = {} found = false for key, value in pairs(hosts_stats) do --print(hosts_stats[key]["name"].."
\n") if((hosts_stats[key]["localhost"] == true) and (hosts_stats[key]["ip"] ~= nil)) then localhosts[key] = hosts_stats[key] -- io.write(key..'\n') -- io.write(ntop.getResolvedAddress(key)..'\n') localhosts[key]["name"] = ntop.getResolvedAddress(key) found = true end end if(found == false) then print("
\n
| ") for key, value in pairs(localhosts) do print(" | "..shortHostName(localhosts[key]["name"]).." | \n") end print("
|---|---|
| "..shortHostName(localhosts[row_key]["name"]).." | \n") for column_key, column_value in pairs(localhosts) do val = " " if(row_key ~= column_key) then rsp = getTraffic(flows_stats, row_key, column_key) if((rsp[1] > 0) or (rsp[2] > 0)) then val = "" if(rsp[1] > 0) then val = val .. ' ' .. localhosts[column_key]["name"] .. '\">'..bytesToSize(rsp[1]) .. ' ' end if(rsp[2] > 0) then val = val .. ' ' .. localhosts[row_key]["name"]..'\">'..bytesToSize(rsp[2]) .. ' ' end end end print("" .. val .. " | \n") end print("