Scapy Sniffing with Custom Actions, Part 1

Scapy has a sniff function that is great for getting packets off the wire, but I recently discovered just how great this feature really is. There’s an argument to pass a function that executes with each packet sniffed. The intended purpose of this function is to control how the packet prints out in the console, allowing you to replace the default .nsummary display with a format of your choice.

In the ScapyDoc.pdf, the prn argument is defined as:

prn: function to apply to each packet. If something is returned, it is displayed. For instance you can use prn = lambda x: x.summary().

Continue reading