【问题标题】:Writing packet information into text file将数据包信息写入文本文件
【发布时间】:2013-05-31 11:26:09
【问题描述】:

我编写了以下代码,以使用 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  

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

【问题讨论】:

    标签: networking lua wireshark packet


    【解决方案1】:

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

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

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

    我没有看到脚本有任何其他问题;如果您仍有问题,我有一个 page on debugging Wireshark Lua scripts 可能会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-12
      • 2017-10-24
      • 2020-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多