diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-07-17 07:11:12 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-07-17 07:11:12 +0000 |
commit | b72837827d9290c7ec50b9e4b9e1a0f194ddccca (patch) | |
tree | 8df663325413d0f92086d740638555de6b779df7 /examples/count-pkts-per-ip.lua | |
parent | Adding upstream version 1.1.0+debian. (diff) | |
download | dnsjit-upstream/1.2.1.tar.xz dnsjit-upstream/1.2.1.zip |
Adding upstream version 1.2.1.upstream/1.2.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples/count-pkts-per-ip.lua')
-rwxr-xr-x | examples/count-pkts-per-ip.lua | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/examples/count-pkts-per-ip.lua b/examples/count-pkts-per-ip.lua deleted file mode 100755 index 9a6908e..0000000 --- a/examples/count-pkts-per-ip.lua +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env dnsjit --- count-pkts-per-ip.lua: count number of packets received from each IP/IPv6 address - -local input = require("dnsjit.input.pcap").new() -local layer = require("dnsjit.filter.layer").new() -local object = require("dnsjit.core.objects") -local ip = require("dnsjit.lib.ip") -local trie = require("dnsjit.lib.trie").new("uint64_t", true) -local getopt = require("dnsjit.lib.getopt").new({}) - -local pcap = unpack(getopt:parse()) -if pcap == nil then - print("usage: "..arg[1].." <pcap>") -end - --- Set up input -input:open_offline(pcap) -layer:producer(input) -local produce, pctx = layer:produce() - --- Read input and count packets -while true do - local obj = produce(pctx) - if obj == nil then break end - local pkt = obj:cast_to(object.IP) or obj:cast_to(object.IP6) - - if pkt ~= nil then - local iplen = 4 - if pkt:type() == "ip6" then - iplen = 16 - end - - local node = trie:get_ins(pkt.src, iplen) - node:set(node:get() + 1) - end -end - --- Print statistics -local iter = trie:iter() -local node = iter:node() - -while node ~= nil do - local npkts = tonumber(node:get()) - local key = node:key() - local ipstr = ip.tostring(key, true) - - print(ipstr.." sent "..npkts.." packets") - iter:next() - node = iter:node() -end |