Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter a pcap dump file for a specific time range

Is there any easy way to create a pcap file for the packets related to a specific datetime range maybe using tshark, tcpdump or another commandline tool?

tshark -R with frame.time seems promising but I haven't been able to work that out yet...

EDIT

The final command:

editcap -F libpcap -A "2013-07-20 23:00:00" -B "2013-07-20 23:20:00" input.pcap output.pcap
like image 846
Filippo Vitale Avatar asked Nov 13 '13 11:11

Filippo Vitale


People also ask

How do I filter tcpdump by protocol?

To filter on TCP and UDP ports, use the port directive. This captures both TCP and UDP traffic using the specified port either as a source or destination port. It can be combined with tcp or udp to specify the protocol, and src or dst to specify a source or destination port.

How do you filter in Tshark?

To specify a capture filter, use tshark -f "${filter}" . For example, to capture pings or tcp traffic on port 80, use icmp or tcp port 80 . To see how your capture filter is parsed, use dumpcap.

What is a PCAP filter?

Pcap expressions are a popular domain-specific language for packet filters, used extensively to capture network traffic during network monitoring or testing. The language is simple but made nontrivial by implicit subformulas and other features that can lead to unex- pected and unwanted results.

Which option do you give Tshark to specify the interface?

The interface name or the number can be supplied to the -i option to specify an interface on which to capture. This can be useful on systems that don't have a command to list them (UNIX systems lacking ifconfig -a or Linux systems lacking ip link show).


1 Answers

What you need is editcap. It's a command-line tool that is part of the Wireshark family.

Check out the man page at http://www.wireshark.org/docs/man-pages/editcap.html.

It takes a pcap file as input, and writes an output one. You may operate on the infile to filter content, for example, with start-time and end-time, packet number ranges, snap packet length, adjusting timestamps (!), etc. It's a great tool.

like image 113
James Avatar answered Sep 19 '22 00:09

James