A Python-based network packet sniffer developed as Task 1 of the CodeAlpha Cybersecurity Internship. This project captures live network traffic and analyzes packet information including source and destination IP addresses, protocols, ports, services, payloads, and packet statistics using the Scapy library.
The project demonstrates the fundamentals of packet sniffing, network protocol analysis, and traffic monitoring while strengthening practical Python programming and cybersecurity skills.
The objective of this project was to:
- Capture live network traffic packets
- Analyze packet structure and contents
- Understand how data flows through a network
- Learn the basics of TCP/IP networking
- Display useful packet information such as:
- Source IP Address
- Destination IP Address
- Protocol
- Source and Destination Ports
- Services
- Packet Length
- Payload Data
- Capture live network traffic
- Supports user-defined packet count
- Detect TCP, UDP and ICMP packets
- Display source and destination IP addresses
- Display source and destination ports
- Detect common network services (HTTP, HTTPS, DNS, FTP, SSH, SMTP, etc.)
- Detect encrypted HTTPS traffic
- Display packet payloads
- Display packet capture time
- Display packet length
- Generate a protocol summary after packet capture
- Validate user input
- Simple command-line interface
- Python 3.13
- Scapy
- Visual Studio Code
- Git
- GitHub
- Kali Linux
- Windows Command Prompt
- The user enters the number of packets to capture.
- Scapy captures live packets from the selected network interface.
- Each packet is inspected individually.
For every packet, the program displays:
- Time
- Source IP Address
- Destination IP Address
- Source Port
- Destination Port
- Service
- Protocol
- Packet Length
- Payload Information
After packet capture is complete, the program displays:
- Total packets captured
- TCP packet count
- UDP packet count
- ICMP packet count
git clone https://github.com/Miracle-Godwin-Ogbo/CodeAlpha_Basic_Network_Sniffer.gitcd CodeAlpha_Basic_Network_SnifferInstall the required Python package using:
pip install -r requirements.txtRecent versions of Kali Linux implement PEP 668, which restricts installing Python packages system-wide using pip.
Install Scapy using Kali's package manager instead:
sudo apt update
sudo apt install python3-scapyAlternative: If you prefer using
requirements.txt, you can run:
pip3 install -r requirements.txt --break-system-packagesThis overrides Kali's package protection and is generally recommended only for testing or virtual machine environments.
python network_sniffer.pysudo python3 network_sniffer.pyNote: Root (
sudo) privileges are required on most Linux distributions to capture live network packets.
How many packets do you want to capture?
10
============================================================
Packet : 1
Time : 00:21:33
Source IP : 172.20.10.3
Source Port : 62509
Destination IP : 140.82.113.26
Destination Port : 443
Service : HTTPS
Protocol : TCP
Packet Length : 84 bytes
Payload : Encrypted HTTPS Data
========================================
CAPTURE SUMMARY
========================================
Total Packets Captured : 10
TCP Packets : 6
UDP Packets : 4
ICMP Packets : 0
========================================
Capture Complete!
- Ensure Python 3 is installed before running the program.
- The program captures only the number of packets specified by the user.
- HTTPS payloads are encrypted and are displayed as Encrypted HTTPS Data.
- Only capture traffic on networks that you own or have explicit authorization to analyze.
The screenshots below demonstrate the development, execution, and testing of the Basic Network Sniffer project on both Windows and Kali Linux.
The project developed and executed within Visual Studio Code.
Demonstrates the program handling invalid user input.
The project running successfully from the Windows Command Prompt.
The project cloned from GitHub and executed successfully on Kali Linux.
- Packet Sniffing
- Network Traffic Analysis
- Scapy
- TCP/IP Networking
- TCP, UDP and ICMP Protocols
- IP Addressing
- Port Numbers
- Common Network Services
- Packet Payload Analysis
- Python Loops
- Conditional Statements
- Dictionaries
- Input Validation
- Python Error Handling
- Export captured packets to PCAP format
- Save packet logs to a file
- Filter packets by protocol
- Filter packets by IP address
- Display MAC addresses
- Display TCP Flags
- Add packet timestamps from the capture itself
- Real-time packet monitoring
- Build a graphical user interface (GUI)
Junior Penetration Tester | Cybersecurity Analyst | Python Developer
Developed during the CodeAlpha Cybersecurity Internship.
https://github.com/Miracle-Godwin-Ogbo
https://www.linkedin.com/in/miracle-godwin-ogbo-19a3a2241
This project was developed for educational purposes as part of the CodeAlpha Cybersecurity Internship. It demonstrates packet sniffing and network traffic analysis using Python and Scapy.
The tool should only be used on networks that you own or where you have explicit authorization to capture network traffic. Unauthorized packet sniffing may violate privacy, organizational policies, or applicable laws.






