【问题标题】:How to get the TCP stream number with a listener?如何通过侦听器获取 TCP 流号?
【发布时间】:2017-03-10 08:31:24
【问题描述】:

我正在分析一个非常大的 PCAP,其中包含许多 HTTP 事务,其中一些是我感兴趣的。我使用 tshark 和 Lua 脚本来查询与过滤器匹配的所有数据包。

tshark -X lua_script:filter.lua -r some.pcap  -q

到目前为止一切顺利。但是,我正在专门寻找一个数据包的 TCP 流号的值,它在 Wireshark 中以名称 tcp.stream 命名。谁能说出我需要对filter.lua 进行哪些更改才能打印?

-- filter.lua
do
    local function init_listener()
        local tap = Listener.new("http","http contains someKeyValue && tcp.port eq 1234")
        function tap.reset()
        end
        function tap.packet(pinfo,tvb,ip)
            print("Found my packet ... now what?")
        end
        function tap.draw()
        end
    end
    init_listener()
end

关于 pinfotvbip 是什么的文档即将发布。

【问题讨论】:

    标签: lua wireshark wireshark-dissector


    【解决方案1】:

    您可以通过Field 访问 TCP 流号。

    local tcp_stream = Field.new("tcp.stream").value
    

    Field 的值是当前数据包的值。您不需要每次都创建一个新的Field。这允许您将Field 设为常量并创建一个返回当前数据包的 TCP 流号的函数。也可以调用Field 值来获取FieldInfo 值,其中可能包含其他有用信息。

    您希望filter.lua 看起来像:

    -- filter.lua
    do
        local function init_listener()
            local get_tcp_stream = Field.new("tcp.stream")
            local tap = Listener.new("http","http contains someKeyValue && tcp.port eq 1234")
            function tap.reset()
            end
            function tap.packet(pinfo,tvb,ip)
                print(tostring(get_tcp_stream()))
            end
            function tap.draw()
            end
        end
        init_listener()
    end
    

    https://www.wireshark.org/docs/wsdg_html_chunked/lua_module_Field.html#lua_class_Field

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-26
      • 1970-01-01
      • 2012-07-27
      相关资源
      最近更新 更多