A Python-based packet sniffer that captures and analyzes network packets, supporting various protocols including Ethernet, IPv4, TCP, UDP, ICMP, ARP, DNS, HTTP, and FTP.
This packet sniffer is a Python script designed for network administrators and cybersecurity enthusiasts to monitor and analyze network traffic. It utilizes raw sockets to capture packets directly from a specified network interface. The captured packets are processed to extract and display detailed information about each packet, including protocol-specific details such as IP addresses, port numbers, and payload data.
- Protocol Support: Handles Ethernet, IPv4, TCP, UDP, ICMP, ARP, DNS, HTTP, and FTP protocols.
- Dynamic Capture Mode: Allows starting and stopping packet capture dynamically from the interactive command line prompt.
- Output Options: Supports saving captured packets to a file in raw text, JSON, or PCAP format.
- Filtering: Capture specific traffic types like
tcp,udp,icmp,arp,dns,http, orftp. - Verbose Logging: Provides detailed logging with options for increased verbosity.
- Cross-platform: Designed to run on Linux (requires root permissions for raw sockets).
-
Clone the repository:
git clone https://github.com/your_username/packet-sniffer.git cd packet-sniffer -
Install dependencies: Ensure Python 3.x is installed. Install the required libraries using pip:
pip install scapy
(If a
requirements.txtis present, you can runpip install -r requirements.txt)
You must run the script with root privileges (sudo) to bind to raw sockets.
Capture packets on a specific network interface (-i or --interface):
sudo python3 packet_sniffer.py -i wlan0Capture specific types of packets using the -f or --filter flag (e.g., tcp, udp, icmp, arp, dns, http, ftp, or all):
sudo python3 packet_sniffer.py -i eth0 -f httpEnable dynamic start/stop of packet capture using the -d or --dynamic flag:
sudo python3 packet_sniffer.py -i eth0 -dOnce started, type start to begin capturing, stop to pause, and exit to quit.
- Raw Output: Append raw packet data to a specified file (
-o).sudo python3 packet_sniffer.py -i wlan0 -o captured_packets.txt
- JSON Output: Save packet details in JSON format to a file (
-oand--json).sudo python3 packet_sniffer.py -i wlan0 -o packets.json --json
- PCAP Output: Save captured packets in PCAP format for analysis in tools like Wireshark (
-oand--pcap).sudo python3 packet_sniffer.py -i wlan0 -o capture.pcap --pcap
Increase output verbosity with the -v or --verbose flag:
sudo python3 packet_sniffer.py -i wlan0 -vThe packet sniffer supports parsing the following protocols:
- Ethernet
- IPv4
- TCP
- UDP
- ICMP
- ARP
- DNS
- HTTP
- FTP
Contributions are welcome! Please fork the repository and create a pull request for any enhancements, bug fixes, or new features. Ensure your code adheres to PEP 8 style guidelines and includes appropriate tests.
- Fork the repository
- Create your feature branch (
git checkout -b feature/YourFeature) - Commit your changes (
git commit -m 'Add some feature') - Push to the branch (
git push origin feature/YourFeature) - Create a new Pull Request