aboutsummaryrefslogtreecommitdiff
path: root/wireshark/tshark/count_tcp_example.lua
diff options
context:
space:
mode:
Diffstat (limited to 'wireshark/tshark/count_tcp_example.lua')
-rwxr-xr-xwireshark/tshark/count_tcp_example.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/wireshark/tshark/count_tcp_example.lua b/wireshark/tshark/count_tcp_example.lua
new file mode 100755
index 000000000..83d81c9e8
--- /dev/null
+++ b/wireshark/tshark/count_tcp_example.lua
@@ -0,0 +1,33 @@
+#!/usr/bin/env lua
+--
+-- (C) 2021 - ntop.org
+--
+
+package.path = "lib/?.lua;" .. package.path
+local tshark = require "tshark"
+
+local pcap_file = "../../tests/pcap/tor.pcap"
+
+local t = tshark:open(pcap_file, "tcp")
+
+if(t == nil) then
+ io.write("Unable to read pcap file "..pcap_file.."\n")
+ exit()
+end
+
+local num_tcp = 0
+
+while(true) do
+ local l = t:read()
+
+ if(l == nil) then break end
+
+ io.write(".")
+ io.flush()
+
+ num_tcp = num_tcp + 1
+end
+
+t:close()
+
+io.write("\nFound "..num_tcp.." TCP packets on pcap "..pcap_file.."\n")