Created
July 7, 2020 18:42
-
-
Save NimishMishra/30bf4b90bf16fee5901e912e2319eb3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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