Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I have tcpdump write to file and standard output the appropriate data?

Tags:

linux

tcpdump

I want to have tcpdump write raw packet data into a file and also display packet analysis into 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?

like image 891
user2565010 Avatar asked Sep 01 '14 10:09

user2565010


People also ask

How do I save a tcpdump output to a file?

The "-w" option lets you write the output of tcpdump to a file which you can save for further analysis. The "-r" option lets you read the output of a file. All you have to do is use the "-r" option with tcpdump command and specify the path of the file you want to read.

What is output format of tcpdump?

The tcpdump can also adjust output formats by using -X for hex or -A for ASCII. # tcpdump -i any -c4 -X tcpdump: data link type LINUX_SLL2 dropped privs to tcpdump tcpdump: verbose output suppressed, use -v[v]...

Where does tcpdump save file?

The Configuration utility creates the tcpdump file and a TAR file that contains tcpdump. These files are located in the /shared/support directory.

How do I specify a protocol in tcpdump?

tcpdump allows you to specify network packets that are either using some port X as source or destination. For example, to capture DNS traffic, you can use port 53 . You could prefix the port keyword with src/dst as src port 53 or dst port 53 and filter it even further.


2 Answers

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
like image 140
cnicutar Avatar answered Sep 23 '22 05:09

cnicutar


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. 
like image 37
ysdx Avatar answered Sep 22 '22 05:09

ysdx