The Network Packet Analyzer is a Python-based GUI application built with tkinter, scapy, and matplotlib 🎨. It’s your go-to tool for capturing, analyzing, and visualizing network packets in real-time with a fun and user-friendly interface 😄. Apply packet filters, view summaries, save data, and enjoy dynamic graphs showcasing traffic trends and protocol distributions 📊.
Perfect for network admins, security geeks, or anyone curious about network traffic! 🕵️♂️
- Packet Capture 🕸️: Snag network packets with custom filters (e.g.,
tcp,udp,port 80). - Real-Time Display 📜: Watch packet summaries scroll in a neat text area.
- Dynamic Visualization 📈:
- Line graph tracking packet capture trends over time ⏱️.
- Pie chart showing protocol distribution (TCP, UDP, ICMP) 🥧.
- Save Captured Data 💾: Export packet summaries to
captured_packets.txt. - Clear Output 🧹: Wipe the text area clean for a fresh start.
- Responsive GUI 🖥️: Font size adjusts dynamically when you resize the window.
- Status Updates 🔔: Stay in the loop with real-time status (e.g., "Capturing packets...", "Idle").
To get this app running, you’ll need:
- Python 🐍: Version 3.6 or higher.
- tkinter 🖼️: Usually comes with Python; powers the GUI.
- scapy 📡: For capturing and analyzing packets.
- matplotlib 📊: For those slick real-time graphs.
- numpy 🔢: Optional, used by
matplotlibfor numerical magic. - Npcap (Windows only) 🪟: Required for packet capturing on Windows.
-
Install Python 🐍:
- Grab Python from python.org and install it.
-
Install Python Packages 📦:
pip install scapy matplotlib
-
Install Npcap (Windows Only) 🪟:
- Npcap is required for
scapyto capture packets on Windows. - Steps:
- Download Npcap from npcap.com.
- Run the installer and follow the prompts.
- Ensure the "Install Npcap in WinPcap API-compatible mode" option is checked.
- Restart your computer if prompted.
- Note: You may need administrative privileges to install Npcap.
- Npcap is required for
-
Run with Admin Privileges 🔐:
scapyneeds administrative/root privileges to capture packets.- On Windows, right-click your terminal (e.g., Command Prompt or PowerShell) and select "Run as administrator".
- On Linux, use
sudo(e.g.,sudo python packet_sniffer.py).
-
Run the Application 🏃♂️:
python packet_sniffer.py
Replace
packet_sniffer.pywith your script’s name. -
GUI Layout 🖱️:
- Filter Entry ✍️: Type a filter (e.g.,
tcp,udp,port 80) to capture specific packets. - Buttons 🛎️:
- Start Capture
▶️ : Kick off packet capturing with your filter. - Stop Capture ⏹️: Pause the capture process.
- Save to File 💾: Save packet summaries to
captured_packets.txt. - Show Graphs 📉: Pop up real-time graphs for trends and protocols.
- Clear Output 🗑️: Clear the packet summary display.
- Start Capture
- Text Area 📄: Shows live packet summaries.
- Packet Count 🔢: Tracks total captured packets.
- Status Bar ℹ️: Displays current state (e.g., "Idle", "Capturing packets...").
- Filter Entry ✍️: Type a filter (e.g.,
-
Capturing Packets 🕵️:
- Enter a filter (optional) and hit Start Capture
▶️ . - Watch packet summaries roll in the text area.
- Click Stop Capture ⏹️ to halt.
- Enter a filter (optional) and hit Start Capture
-
Visualizing Data 📊:
- Click Show Graphs 📉 to see:
- A line graph of packets captured over time 📈.
- A pie chart of protocol distribution (TCP, UDP, ICMP) 🥧.
- Graphs refresh every second for real-time vibes ⏰.
- Click Show Graphs 📉 to see:
-
Saving Data 💾:
- After stopping, click Save to File to dump summaries to
captured_packets.txt.
- After stopping, click Save to File to dump summaries to
The app is packed into a single Python script with these key pieces:
-
PacketSnifferApp Class 🖥️:
- Runs the show for GUI and packet capturing.
- Attributes:
master: Thetkinterroot window.running: Boolean to toggle packet capturing.packet_count: Counts captured packets.captured_packets: Stores captured packets.protocol_counter: Tracks protocol distribution (TCP, UDP, ICMP).time_data: Logs packet counts for trends.
- Methods:
__init__: Sets up the GUI and scaling.update_layout: Tweaks font size based on window size.start_sniffing: Fires up packet capture in a thread.stop_sniffing: Stops capturing.sniff_packets: Grabs packets withscapy.display_packet: Processes and shows packet info.save_to_file: Saves summaries to a file.clear_output: Clears the text area.show_graphs: Spins up real-time graphs.
-
main Function 🚪:
- Boots up the
tkinterwindow and starts the app.
- Boots up the
tkinter🖼️: Builds the GUI (buttons, text area, etc.).scapy📡: Captures and filters packets.threading🧵: Runs capturing in a separate thread to keep the GUI smooth.matplotlib📊: Powers line graphs and pie charts.collections.Counter🔢: Counts protocol occurrences.
- Built with
tkinterfor a clean, responsive layout. - Widgets are packed or gridded for tidy placement.
- Text area font scales with window size for readability 📏.
- Buttons are grouped in a frame for a polished look.
- Uses
scapy’ssnifffunction to grab packets. - Runs in a separate
Threadto keep the GUI responsive. - Filters (e.g.,
tcp,port 80) are passed tosniff. display_packetupdates the GUI and tracks protocols.
- Packet Traffic Graph 📉:
- Line graph plots packet counts over time.
- Refreshes every second via
FuncAnimation.
- Protocol Distribution 🥧:
- Pie chart shows TCP, UDP, ICMP percentages.
- Uses red, green, blue for visual pop 🌈.
- Updates every second with
FuncAnimation.
- Packets are stored in
captured_packets(list). save_to_filewrites summaries tocaptured_packets.txt.
- Privileges 🔐: Needs admin/root access for
scapy. - Platform 🖥️: Tested on Windows/Linux; macOS may need tweaks.
- Filters ✍️: Invalid filter strings can cause errors—stick to
scapysyntax. - Performance 🐢: High packet volumes may slow the GUI or eat memory.
- Visualization 📊: Graphs may lag with tons of packets.
- Advanced Filters 🔎: Add a dropdown for common filters or validate syntax.
- Packet Details 📋: Show source/destination IP, payload, etc.
- Export Formats 📄: Support PCAP, CSV, or JSON exports.
- Performance Boost ⚡: Buffer packets or limit displayed data.
- Cross-Platform Love 🌍: Ensure macOS compatibility.
- Error Handling 🛡️: Better messages for bad filters or missing privileges.
- "Permission Denied" Error 🚫:
- Run with admin privileges (e.g.,
sudoon Linux or "Run as administrator" on Windows).
- Run with admin privileges (e.g.,
- No Packets Captured 😕:
- Check if the network interface is active and traffic exists.
- Verify filter syntax (e.g.,
tcpnotTCP).
- GUI Freezes 🥶:
- Stop capturing or reduce packet rate.
- Graphs Not Updating 📉:
- Ensure
matplotlibis installed and no errors during graph setup.
- Ensure
- Npcap Issues 🪟:
- Reinstall Npcap or ensure WinPcap compatibility mode is enabled.
This project is licensed under the GNU General Public License v3.0 🗽. You’re free to use, modify, and share it, as long as you keep it open-source and share your changes under the same license. See LICENSE for details.
Got questions or ideas? Reach out to the project maintainer or open an issue on the repo (if available). Let’s make this tool even cooler! 😎