2
votes

i wrote the following code to output source address and destination address of all packets that are in a .pcap file to a text file using lua and tshark.

#!/usr/bin/lua

do
    local file = io.open("luawrite", "w")
    local function init_listener()
            local tap = Listener.new("ipv6")
            function tap.packet(pinfo, tvb)
                    local srcadd = pinfo.src
                    local dstadd = pinfo.dst
                    file:write(tostring(srcadd), "\t", tostring(dstadd)"\n")
            end
    end
end  

I am running this script using the following command:

tshark -r wireless.pcap -xlua_script:MyScript.lua  

Why is nothing being written in my text file? Is there something wrong on the code? Help is very much appreciated. Thanks!

1

1 Answers

3
votes

Probably because you are missing a comma before "\n":

---------------------------------------------------vv-----
file:write(tostring(srcadd), "\t", tostring(dstadd), "\n")

It may be useful to check for file value returned by the open call.

I don't see any other problems with the script; if you still have issues, I have a page on debugging Wireshark Lua scripts that may help.