How can I have tcpdump write to file and standard

2019-03-07 23:31发布

I want to have tcpdump write raw packet data into a file and display packet analysis in standard output as the packets are captured (by analysis I mean the lines it displays normally when -w is missing). Can anybody please tell me how to do that?

标签: linux tcpdump
2条回答
Fickle 薄情
2楼-- · 2019-03-08 00:00
tcpdump ${ARGS} &
PID=$!
tcpdump ${ARGS} -w ${filename}
kill $PID
查看更多
家丑人穷心不美
3楼-- · 2019-03-08 00:04

Here's a neat way to do what you want:

tcpdump -w - | tee somefile | tcpdump -r -

What it does:

  • -w - tells tcpdump to write binary data to stdout
  • tee writes that binary data to a file AND to its own stdout
  • -r - tells the second tcpdump to get its data from its stdin
查看更多
登录 后发表回答