How can I have tcpdump write to file and standard output the appropriate data?
Here's a neat way to do what you want:
tcpdump -w - -U | tee somefile | tcpdump -r -
What it does:
-w -
tellstcpdump
to write binary data tostdout
-U
tellstcpdump
to write each packet to stdout as it is received, rather than buffering them and outputting in chunkstee
writes that binary data to a file AND to its ownstdout
-r -
tells the secondtcpdump
to get its data from itsstdin
Since tcpdump 4.9.3 4.99.0, the --print
option can be used:
tcpdump -w somefile --print
Wednesday, December 30, 2020, by [email protected], denis and fxl.
Summary for 4.99.0 tcpdump release
[...]
User interface:
[...]
Add --print, to cause packet printing even with -w.