Problem Statement:
Monitoring network traffic is essential for detecting malicious activities such as unauthorized access, data exfiltration, or DDoS attacks. Traditional packet sniffers lack advanced filtering and logging features.
Solution:
By designing a Python-based advanced packet sniffer that:
I was able to solve this problem.
A. Packet Sniffing Module
Code Snippet:
from scapy.all import sniff, IP, TCP, UDP
def packet_callback(packet):
if IP in packet:
print(f"Source: {packet[IP].src}, Destination: {packet[IP].dst},
Protocol: {packet[IP].proto}")
with open("packet_log.txt", "a") as log:
log.write(f"{packet.summary()}\n")
print("Sniffing packets... Press Ctrl+C to stop.")
sniff(prn=packet_callback, store=0)
B. Traffic Anomaly Detection Module
Analyzed captured packets for anomalies like:
High data transfer volume.
Traffic from suspicious IP addresses.
Code Snippet:
import pandas as pd
def analyze_traffic(log_file):
df = pd.read_csv(log_file, names=["Summary"])
print("Analyzing traffic for anomalies...")
print(df.head()) # Perform IP address analysis or anomaly detection
C. Output & Results
Copyright © 2024 Nosagie