Free Online Analysis of PCAP Files (Mac)
Get a FREE automated analysis of Packet Capture (PCAP) files, to discover malicious activity, security vulnerabilities and other network events.

Get a FREE automated analysis of Packet Capture (PCAP) files, to discover malicious activity, security vulnerabilities and other network events.
See also: Creating PCAP files on Windows or Linux.
netstat -nr | grep default
to find which
interface has
the Default Gateway configured. Take note of the interface's (device) name.sudo tcpdump -vni <interface-name> -s 0 -w <filename.pcap> -c 100000
If you're using macOS, you already have everything you need to capture network traffic, as it has included tcpdump since the early '90ss. Tcpdump is a command-line network traffic capture and analysis tool that was released in 1988. It is available for most Unix-like operating systems, such as Linux, macOS, FreeBSD, OpenBSD, Solaris, HP-UX, AIX, and OpenWRT (the router OS). Tcpdump uses libpcap library to capture packets and natively supports the pcap capture format.
If, for some reason, you prefer to avoid the command-line interface, you can install the Wireshark package to capture network traffic and much more, but that should be the subject of a completely different post. (Download link here: ARM / Intel CPU). For the rest of this guide, I'll assume you are comfortable working with a macOS terminal.
To open the terminal, click the Launchpad icon in the
Dock, type “Terminal” in the search field,
then click Terminal. Alternatively, in the Finder
, open the /Applications/Utilities
folder,
then double-click Terminal.
Although tcpdump can capture traffic from all interfaces simultaneously, I strongly advise against this practice unless the suspected traffic could appear on multiple interfaces. This scenario might occur if you are capturing traffic on a gateway device, where traffic crosses the OS while originating at one interface and is routed through another. However, it is unlikely that your Apple device is your network's gateway, so it is safe to skip this for now.
Type netstat -nr | grep default
to find the device name:
The netstat -nr command lists all routes configured on the host. The default gateway route always starts with the word 'default,' followed by the default gateway IP address (e.g., 172.16.0.254) and the local interface (device) that is connected to the same network/subnet (e.g., en0).
Under normal circumstances, there should be only one interface for which the default gateway is configured. However, as you can see, my MacBook has two tun interfaces configured for VPN networking, but these are not where my suspected traffic goes through. If you find no default gateway (which means you cannot route traffic outside) or if you find multiple default gateways configured and cannot determine which interface should be sniffed, you might need to perform several separate captures and analyze all of them. A good starting point would be a non-tun interface, preferably one with an IPv4 address (the 'fe80::..' addresses are IPv6).
sudo su
command or simply add sudo before the tcpdump command: sudo tcpdump
.
ls -lh
. A useful trick is to watch the changing file size
until it reaches the desired target using the watch command, like this:
watch 'ls -lh capture.pcap'
. You can stop the capture at any time by pressing
Ctrl + C.
Here’s how I would perform a full-packet capture of 100K packets with tcpdump:
sudo tcpdump -vni <interface-name> -s 0 -w <filename.pcap> -c 100000
Here’s my command with:
You can now verify that the capture was performed correctly by reading and parsing it with the
tcpdump -nr sample.pcap
command. To limit the output to the first 20 packets, you
can use head
-n 20. Alternatively, you can pipe the output to other tools such as
less, which allows you to
scroll through the entire capture, or wc -l, which lets you count the captured
packets.
Voila, we got our forensic-grade pcap capture using tcpdump!
Getting error messages from tcpdump? See this list of Common tcpdump Errors and Solutions.