From cc206b31248207b41c68eeb63cbc9f69c0a17217 Mon Sep 17 00:00:00 2001 From: Shreejan Date: Sat, 8 Oct 2022 14:11:19 +0530 Subject: [PATCH] packet sniffer in python --- scripts/packet_sniffer/README.md | 23 +++++++++++++++++++++++ scripts/packet_sniffer/main.py | 20 ++++++++++++++++++++ scripts/packet_sniffer/requirements.txt | 1 + 3 files changed, 44 insertions(+) create mode 100644 scripts/packet_sniffer/README.md create mode 100644 scripts/packet_sniffer/main.py create mode 100644 scripts/packet_sniffer/requirements.txt diff --git a/scripts/packet_sniffer/README.md b/scripts/packet_sniffer/README.md new file mode 100644 index 0000000..7558419 --- /dev/null +++ b/scripts/packet_sniffer/README.md @@ -0,0 +1,23 @@ +# PACKET SNIFFER + +Hi all! This is a packet sniffer in python. + +## Libraries +I have used ```scapy``` library + +## Getting started +1. First of all - +``` +pip install requirements.txt +``` + +2. Secondly - +``` +python main.py +``` +OR +``` +sudo python3 main.py +``` + +That's all. This is how we can use the packet sniffer. \ No newline at end of file diff --git a/scripts/packet_sniffer/main.py b/scripts/packet_sniffer/main.py new file mode 100644 index 0000000..76a3dc2 --- /dev/null +++ b/scripts/packet_sniffer/main.py @@ -0,0 +1,20 @@ +import scapy.all as scapy +from scapy.layers import http + + +def sniffing(interface): + scapy.sniff(iface=interface, + storage=False, prn=process_packet, filter='tcp') + + +def process_packet(packet): + if packet.haslayer(http.HTTPRequest): + print(packet[http.HTTPRequest].Host) + + +def main(): + sniffing("Wi-Fi") + + +if __name__ == "__main__": + main() diff --git a/scripts/packet_sniffer/requirements.txt b/scripts/packet_sniffer/requirements.txt new file mode 100644 index 0000000..c975eaf --- /dev/null +++ b/scripts/packet_sniffer/requirements.txt @@ -0,0 +1 @@ +scapy==2.4.5