将包信息写入文本文件

时间:2013-06-04 22:18:43

标签: networking lua wireshark packet

我编写了以下代码,使用lua和tshark将.pcap文件中所有数据包的源地址和目标地址输出到文本文件。

#!/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  

我使用以下命令运行此脚本:

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

为什么我的文本文件中没有写入任何内容?代码有问题吗?非常感谢帮助。谢谢!

1 个答案:

答案 0 :(得分:3)

可能是因为您在“\ n”之前缺少逗号:

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

检查file电话返回的open值可能很有用。

我没有看到脚本有任何其他问题;如果您仍有问题,我可以提供page on debugging Wireshark Lua scripts

相关问题