Filter udp packets using lua script
So I have tshark and lua script which i am trying to run. I am running with the command:
sudo tshark -X lua_script:luascript.lua -c 100
Where my lua scrpit looks like this:
do
packets = 0;
file = io.open("result.txt","a")
local function init_listener()
local tap = Listener.new(nil,"ip.addr == 10.0.2.15&&udp")
function tap.reset()
packets = 0;
end
function tap.packet()
packets = packets + 1
io.output(file)
end
function tap.draw()
print("Packets to/from 10.0.2.15",packets)
end
end
init_listener()
io.close(file)
end
So when i ran tshark I get each packet ouputs to the command line like this one:
98 5.300306453 142.250.179.136 → 10.0.2.15 TCP 60 443 → 54114 [ACK] Seq=1 Ack=1031 Win=65535 Len=0
And everytime udp packet comes up i want to save it to output file(with all the information). So indeed tap.packet() captures Those packets but what i want is to write them to output file using lua script.
How do i do that?