Linux – run tcpdump not to interpert packet contents

linuxnetworkingtcpdumptraffic

What options should I run tcpdump with to have it just do a hex dump of packets without trying to interpret its contents? Running it astcpdump -e -v -x or similar attempts to interpret layers, however I don't want it.

I want what tshark does:

% sudo tshark -xxx -i eth0
...

Best Answer

The closest two solutions I can find for this are these

  1. Postprocess to remove the decoding.

    tcpdump -nXX -i eth0 | sed $'s/^[^ \t].*//'
    

    This isn't perfect as the formats are a little different.

    tshark
    0000  52 54 00 12 35 02 08 00 27 0f db b3 08 00 45 00   RT..5...'.....E.
    0010  00 54 2a 4d 40 00 40 01 e9 43 0a 00 02 0f 0a 0f   .T*M@.@..C......
    0020  10 fb 08 00 ab 06 1e b5 00 01 00 3f ab 57 00 00   ...........?.W..
    
    tcpdump
    0x0000:  0008 9bbd ab8a 001d aadd cb68 0800 4500  ...........h..E.
    0x0010:  0028 3ec8 4000 7e06 a075 0a0a 0510 0a0f  .(>.@.~..u......
    0x0020:  046a cb6a 0016 7049 a307 5eaf 8afb 5010  .j.j..pI..^...P.
    
  2. Write to a data file and use tshark to interpret it (possibly on another machine).

    tcpdump -w /tmp/capture.dat -i eth0
    tshark -r /tmp/capture.dat -xxx
    

    Here, since we're using tshark to process the capture file, the output will be exactly as you want. You can do "nasty" things like running tshark remotely if necessary:

    ssh -zq remote_host tshark -r - -xxx < /tmp/capture.dat
    
Related Question