Search code examples
timestamptcpdump

time stamp in tcpdump file


I have written a linux script to dump the packets using tcpdump command to a file dcn.pcap to max limit of 20MB. Is there anyway to add the timestamp to the filename ? The time stamp from the beginning of the file like 2014_date_time.pcap

tcpdump -w dcn.pcap -C 20 -i eth0 -s 65535 dst net 244.11.11 

Solution

  • Of course you can, just like this(assume you use bash and have superuser privileges to use tcpdump):

    date +'%Y-%m-%d_%H:%M:%S' | xargs -I {} bash -c "tcpdump -C 20 -i eth0 -s 65535 dst net 244.11.11 -w ./{}.pcap"