Skip to content

Instantly share code, notes, and snippets.

@thepacketgeek
Created October 7, 2013 23:20
Show Gist options
  • Save thepacketgeek/6876717 to your computer and use it in GitHub Desktop.
Save thepacketgeek/6876717 to your computer and use it in GitHub Desktop.
Using the scapy 'prn' argument, pass an object along with packet in a sniff(), s(), or sr() function.
# define API options
options = {"url": "http://hosted.app/api/packets", "token": "supersecretusertoken"}
# create parent function with passed in arguments
def customAction(options):
# uploadPacket function has access to the options object because they are 'closed' in the nested function
def uploadPacket(packet):
# upload packet, using passed arguments
headers = {'content-type': 'application/json'}
r = requests.post(options["url"], data=json.dumps(packet,options["token"]), headers=headers)
return uploadPacket
sniff(prn=customAction(options))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment