Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

🔎 Python Network Sniffer

A basic network packet sniffer built with Python and Scapy, developed as part of the CodeAlpha Cybersecurity Internship — Task 1.

The project demonstrates how network packets can be captured and inspected in real time, helping build a practical understanding of network communication and cybersecurity fundamentals.

📌 Project Overview

A network is constantly sending and receiving packets. Each packet contains information that helps devices communicate, such as source and destination addresses, protocols, ports, and sometimes application data.

This project uses Scapy to capture packets from the local machine and display useful information about them directly in the terminal.

🚀 Features

  • Capture live network packets
  • Display source IP addresses
  • Display destination IP addresses
  • Identify TCP and UDP traffic
  • Display source and destination ports
  • Detect packets containing raw payload data
  • Display packet information in a readable format
  • Automatically stop after capturing a specified number of packets

🛠️ Technologies Used

  • Python 3
  • Scapy

📂 Project Structure

CodeAlpha_NetworkSniffer/ │ ├── sniffer.py └── README.md

⚙️ How It Works

The program uses Scapy’s sniff() function to capture packets.

For every captured packet, the program:

  1. Checks whether the packet contains an IP layer.
  2. Extracts the source IP address.
  3. Extracts the destination IP address.
  4. Checks whether the packet uses TCP or UDP.
  5. Extracts the source and destination ports.
  6. Checks whether the packet contains a raw payload.
  7. Displays the information in the terminal.

The current version captures 10 packets before automatically stopping.

📦 Installation

Make sure Python 3 is installed on your computer.

Install Scapy with:

pip install scapy

▶️ Running the Sniffer

Run the program from your terminal:

python sniffer.py

Depending on your operating system, packet capture may require administrator/root privileges.

Windows

You may also need Npcap for packet capture.

Linux/macOS

You may need to run the program with appropriate permissions, for example:

sudo python3 sniffer.py

📊 Example Output

TCP | 192.168.1.5:52341 --> 142.250.72.14:443 TCP | 142.250.72.14:443 --> 192.168.1.5:52341 UDP | 192.168.1.5:5353 --> 224.0.0.251:5353

The exact output will depend on the network activity occurring on the machine while the program is running.

🔐 Understanding Encrypted Traffic

Modern protocols such as HTTPS use encryption to protect application data.

A packet sniffer can still observe network-level information such as IP addresses, ports, and protocols, but encrypted application data is not normally available as readable plaintext.

This project helped demonstrate an important cybersecurity concept:

Being able to capture network traffic does not mean being able to read protected application data.

🎯 What I Learned

Building this project helped me develop a practical understanding of:

  • How network packets are structured
  • IP addressing
  • TCP and UDP communication
  • Source and destination ports
  • Packet capture
  • Basic network traffic analysis
  • The role of encryption in network security
  • Using Python for cybersecurity tasks
  • Working with the Scapy library

🔮 Future Improvements

Possible improvements for future versions include:

  • Add packet filtering
  • Add protocol statistics
  • Add timestamps
  • Save captured packets to a file
  • Export packet information to CSV
  • Add a graphical user interface
  • Add more protocol support
  • Improve packet analysis and visualization

⚠️ Ethical & Legal Use

This project is intended for educational purposes and authorized security testing.

Only capture or analyze network traffic on systems and networks that you own or have explicit permission to monitor.

Do not use this tool to intercept private communications, credentials, or other people’s network traffic without authorization.

👨‍💻 Author

Dike Dickson

Cybersecurity | Python | Networking

Built as part of the CodeAlpha Cybersecurity Internship — Task 1.

⭐ If you’re learning cybersecurity and Python, feel free to explore the project and build upon it.

About

Basic Python network sniffer built with Scapy as part of the CodeAlpha Cybersecurity Internship — Task

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages