1

I want to leave something like tcpdump running for up to a week and therefore make its output as concise as possible to reduce file size and speed up post-capture analysis.

All I need to to do is log the first instance of each packet source or destination (IP address and port) so I can build up a picture of what devices are communicating with my server (or vice versa).

So, once it sees a packet from IP address 192.168.1.10 to port 80, no longer capture any more packets from that address to that port.

Bonus points if it can build up a table of packet counts from each source/to each destination.

The best I've come up with so far is to run tcpdump with the -t and -q options (no timestamps and quiet, respectively) and run the output through sort and uniq to reduce (but not eliminate) the duplicates. Packets to the same destination port but from different source ports slip through this net for example.

6
  • You won't be able to do that with just tcpdump. You'll want to filter on tcp packets, that will at least filter layers 2 and 3 since you are only interested in IP:Port in the packet. For post analysis, look at tshark, it has spectacular options for parsing pcaps and is much more efficient for larger ones than the wireshark GUI.
    – MaQleod
    Commented May 3, 2017 at 15:31
  • It might be useful to use tcpdump's -G feature, combined with -w, to write manageable sized pcap files, which can be post-processed after the specified interval, into a more condensed format. Commented May 3, 2017 at 16:51
  • You just need the connection tuple or really the packet content ? In the first case I think that some iptables rule would be enough, to do logging for each new packet. It seems to me that the bonus points are contradictory to your first goal, as maintaining a count means having the need to see all packets and not stop after the first one. Commented May 3, 2017 at 19:31
  • @PatrickMevzek, just the IP address and port. I see your point; I meant if we have to continue capturing the packets, then a count would be nice.
    – Darren
    Commented May 3, 2017 at 19:36
  • 1
    Just write a script and pipe the output of tcpdump into it. Should be doable with any arbitrary programming language.
    – Tesseract
    Commented May 4, 2017 at 4:29

0

You must log in to answer this question.

Browse other questions tagged .