wireshark - Tshark - 如何仅使用 tshark 显示 tcp 播放负载的解剖树?
问题描述
我正在编写一个wireshark 解剖器。我想在控制台中显示解剖树。
所以我尝试了:
tshark -V
它将显示如下内容:
Frame 105: 69 bytes on wire (552 bits)...
...
Ethernet II, Src: Giga-Byt_97:b3:26 (e0:d5:5e:97:b3:26), Dst: Cradlepo_68:04:37 (00:e0:1c:68:04:37)
...
Internet Protocol Version 4, Src: 192.168.1.153, Dst: 192.168.1.99
...
Transmission Control Protocol, Src Port: 7555, Dst Port: 50555, Seq: 10182, Ack: 485, Len: 15
....
erlang term
PackageLength: 11
compressFlag: 0
m_system_hb_toc(2) [SmallTuple: 2]
time: 1589549432 [Int]
但只有最后一部分是我需要的:
erlang term
PackageLength: 11
compressFlag: 0
m_system_hb_toc(2) [SmallTuple: 2]
time: 1589549432 [Int]
我曾尝试使用“-T 字段”和 -e 选项,但找不到任何帮助。
这是我的解剖器的代码:
local tcpPortLs = {7555}
local SIZE_LEN = 4
local pErlangExt = Proto("ErlangExt", "erlang term")
local fLen = ProtoField.uint32("ErlangExt.len", "PackageLength", base.DEC)
local fCompressFlag = ProtoField.string("ErlangExt.compressFlag", "compressFlag", base.ASCII)
local fBytes = ProtoField.bytes("ErlangExt.data", "PackageData", base.COLON)
pErlangExt.fields = {
fLen,
fBytes,
fCompressFlag,
}
local function msg_pdu_length(buf, pkt, offset)
local size_tvbr = buf:range(offset, SIZE_LEN)
local size = size_tvbr:uint()
return size + SIZE_LEN
end
local function _headBytes(n, dataBuf)
local head = dataBuf(0, n)
if dataBuf:len() == n then
return head, nil
end
local tailDataBuf = dataBuf(n, dataBuf:len() - n)
return head, tailDataBuf
end
local function _addToGroup()
-- ...
end
local function _calcMainTree()
-- ...
end
local function msg_proto_dissector(buf, pkt, root)
local dataLenBuf, metaAndDataBytes = _headBytes(SIZE_LEN, buf)
local detail = root:add(pErlangExt, buf)
local dataLen = dataLenBuf:uint()
detail:add(fLen, dataLenBuf, dataLen)
local zlibFlagBuf, tupleDataBuf = _headBytes(1, metaAndDataBytes)
local zlibFlag = zlibFlagBuf:uint()
detail:add(fCompressFlag, zlibFlagBuf, zlibFlag)
local dataRoot = detail:add(fBytes, tupleDataBuf)
pkt.cols.protocol = "ErlangExt"
local tree = _calcMainTree(tupleDataBuf, zlibFlag)
_addToGroup(dataRoot, tree)
end
function pErlangExt.dissector(buf, pkt, root)
local pktLen = buf:len()
if pktLen ~= buf:reported_len() then
return 0
end
dissect_tcp_pdus(buf, root, 4, msg_pdu_length, msg_proto_dissector)
return pktLen
end
local tcp_encap_table = DissectorTable.get("tcp.port")
for _, port in pairs(tcpPortLs) do
tcp_encap_table:add(port, pErlangExt)
end
并且捕获的数据是https://github.com/cmingjian/testData/blob/master/stage.pcapng
如何只显示我需要的数据?谢谢。
解决方案
也许tshark -O ErlangExt
会为您提供您正在寻找的结果?您仍将获得所有较低层(以太网、IP、TCP)的摘要行,但只会扩展您的 ErlangExt 数据。
-O < protocols >
Similar to the -V option, but causes TShark to only show a detailed view of the comma-separated list of protocols specified, and show only the top-level detail line for all other protocols, rather than a detailed view of all protocols. Use the output of "tshark -G protocols" to find the abbreviations of the protocols you can specify.
推荐阅读
- linux - Bash:如何在一行上匹配特定数字时为一行添加前缀
- python-2.7 - ImportError:没有名为 pathlib 的模块
- java - 在外部 iframe 中加载 Spring Webflux 应用程序
- python - 永久保留python虚拟环境
- spring - JSP 模板中的会话属性
- linux-kernel - tty_insert_flip_string 翻转位
- java - 如何使用附加接口扩展枚举?
- php - 我无法使用控制器中的 id 渲染数据表
- php - 如何在 CodeIgniter3 上获取下一个和上一个 id?
- arrays - 将字符串数组复制到字符串指针数组