Skip to content

Instantly share code, notes, and snippets.

@NimishMishra
Created July 7, 2020 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NimishMishra/30bf4b90bf16fee5901e912e2319eb3a to your computer and use it in GitHub Desktop.
Save NimishMishra/30bf4b90bf16fee5901e912e2319eb3a to your computer and use it in GitHub Desktop.
from collections import Counter
from scapy.all import sniff
packet_counts = Counter()
def custom_action(packet):
key = tuple(sorted([packet[0][1].src, packet[0][1].dst]))
packet_counts.update([key])
return f"Packet #{sum(packet_counts.values())}: {packet[0][1].src} ==> {packet[0][1].dst}"
sniff(filter="ip", prn=custom_action, count=10)
print("\n".join(f"{f'{key[0]} <--> {key[1]}'}: {count}" for key, count in packet_counts.items()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment