View only the network traffic that exits the mac

Hi,
I'm using tcpdump and Wireshark to inspect the network packets that are received and sent from my mac. I'm inspecting the traffic from WiFi interface, but the problem is that the tools display also the traffic that don't exit the system, e.g. the ones that are blocked by the firewall.
Is it possible to somehow see the traffic that for sure left the mac?

e.g.

  1. make a UDP or TCP connection to a remote address, ADDR_1.
  2. start sending/receiving packets
  3. block all the traffic, received & sent, to the ADDR_1 using e.g. pf rules
  4. Wireshark & tcpdump will still show for some time(probably until TCP timeout) the outgoing traffic to ADDR_1, even if the packets are not leaving the mac because are blocked by the firewall. In this case, is it possible to filter out this packets so they are not displayed by the tools?

Thanks

For testing purposes, connecting via wired to a managed switch and mirroring the switchport is probably the easiest approach. With that, you can see all of the packet departures and without involving the host software or apps.

Within macOS, it's probably possible to use pfctl for this logging if not also for port mirroring, but I don't have a way to test either right now.

pfctl manages one of the macOS firewalls, so it's good at blocking stuff.

Related:

https://krypted.com/mac-security/a-cheat-sheet-for-using-pf-in-os-x-lion-and-up/

https://www.openbsdhandbook.com/pf/logging/

Thanks for the suggestions.
I've tried in the past with an external router and it works fine. But in my case I need to run this directly on my mac, in "real-time", not to have the special external setup.

I'll have a look with the pfctl, but might also be complicated. because I'm already modifying this from another app, and I need to add extra things for the logging.

View only the network traffic that exits the mac
 
 
Q