Skip to content

Instantly share code, notes, and snippets.

@thepacketgeek
Last active December 24, 2015 22:59
Show Gist options
  • Save thepacketgeek/6876520 to your computer and use it in GitHub Desktop.
Save thepacketgeek/6876520 to your computer and use it in GitHub Desktop.
Run a custom function on every packet sniffed with scapy
## Import Scapy module
from scapy.all import *
## Create a Packet Count var
packetCount = 0
## Define our Custom Action function
def customAction(packet):
global packetCount
packetCount += 1
return "Packet #%s: %s ==> %s" % (packetCount, packet[0][1].src, packet[0][1].dst)
## Setup sniff, filtering for IP traffic
sniff(filter="ip",prn=customAction)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment