I want to run tshark on a Raspberry Pi after booting or for a defined period of time and save the captured packets into a file. This file should then be accessible from Wireshark on my Windows laptop. I want to do this because I want to capture packets for example when I am not at home and then can analyze the captured data when I am back home. Is that possible? How can I start capturing after booting or for a defined period of time into a file and then send it to Wireshark on my laptop? asked 09 Feb '16, 07:58 Vin |
2 Answers:
Just copy the capture file in the same way you would transfer any other file from the Pi, e.g. scp, or samba. Note that capturing for an extended period using tshark may either:
The former can be fixed by using dumpcap rather than tshark, the same files are produced, but dumpcap doesn't retain any state so doesn't have an ever increasing memory usage. The latter can only be fixed by providing the Pi with more disk space, or capturing in a "ring" of files, but note that when the ring "wraps", the earliest files are lost. See the answered 09 Feb '16, 08:06 grahamb ♦ |
That would depend on the OS you're running on your RPi - and Linux isn't "the OS", a particular Linux distribution is "the OS", and the answer may differ between distributions. (System V init? systemd? etc.)
For dumpcap:
where {N} is the number of seconds for which you want it to capture (which can be a large number, so you can, for example, capture for an entire day with {N} = 86400) and {filename} is the name of the file to which to write. Tcpdump, unfortunately, doesn't have a "stop capturing after {N} seconds" option. answered 09 Feb '16, 12:37 Guy Harris ♦♦ I run Raspbian on my Raspberry Pi. How can I start capturing after booting there? I read that it can be done by adding a line in /etc/rc.local but I am not sure what to put there. (15 Feb '16, 15:24) Vin |
Similarly, tcpdump can be used to dump to a file; if run with the
-w
flag, it'll just write raw packet data to the file without interpreting it, and thus won't maintain any memory-eating state. If you have it, but not any of Wireshark's components, installed on the RPi, you won't need to install Wireshark just to get dumpcap.