Skip to content

AkshatM1707/Packet-Sniffer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Packet Sniffer

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.

Overview

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.

Features

  • 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, or ftp.
  • Verbose Logging: Provides detailed logging with options for increased verbosity.
  • Cross-platform: Designed to run on Linux (requires root permissions for raw sockets).

Installation

  1. Clone the repository:

    git clone https://github.com/your_username/packet-sniffer.git
    cd packet-sniffer
  2. Install dependencies: Ensure Python 3.x is installed. Install the required libraries using pip:

    pip install scapy

    (If a requirements.txt is present, you can run pip install -r requirements.txt)

Usage

You must run the script with root privileges (sudo) to bind to raw sockets.

Basic Usage

Capture packets on a specific network interface (-i or --interface):

sudo python3 packet_sniffer.py -i wlan0

Filtering Traffic

Capture 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 http

Dynamic Mode

Enable dynamic start/stop of packet capture using the -d or --dynamic flag:

sudo python3 packet_sniffer.py -i eth0 -d

Once started, type start to begin capturing, stop to pause, and exit to quit.

Output Options

  • 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 (-o and --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 (-o and --pcap).
    sudo python3 packet_sniffer.py -i wlan0 -o capture.pcap --pcap

Verbose Logging

Increase output verbosity with the -v or --verbose flag:

sudo python3 packet_sniffer.py -i wlan0 -v

Supported Protocols

The packet sniffer supports parsing the following protocols:

  • Ethernet
  • IPv4
  • TCP
  • UDP
  • ICMP
  • ARP
  • DNS
  • HTTP
  • FTP

Contributing

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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/YourFeature)
  3. Commit your changes (git commit -m 'Add some feature')
  4. Push to the branch (git push origin feature/YourFeature)
  5. Create a new Pull Request

About

A powerful Python-based packet sniffer for network analysis, supporting Ethernet, IPv4, TCP, UDP, ICMP, ARP, DNS, HTTP, and FTP protocols. Capture and analyze network traffic dynamically with options for saving to raw, JSON, or PCAP formats. Ideal for network administrators and cybersecurity enthusiasts.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages