Question: Objective: Our primary objective is to capture and analyze network tra 8 ic in real - time a crucial task in network monitoring: 1 .

Objective: Our primary objective is to capture and analyze network tra8ic in real-time a crucial task in network monitoring: 1. Log detailed information about each packet, including source and destination addresses, protocol types, and packet sizes. 2. Calculate and display a comprehensive set of network metrics to thoroughly understand your networks performance. Project Knowledge Requirements: The lab covers all the coding concepts required for this project, but this document highlights additional knowledge you may need. Adjust the lab knowledge to meet the project requirements. Project Components: 1. Packet Capture and Parsing Utilize Scapy to capture packets at the Ethernet, IP, TCP, and UDP layers. Process and log essential packet details: Ethernet Layer: Source and destination MAC addresses. IP Layer: Source, destination IP addresses, and protocol used. TCP/UDP Layers: Source and destination ports, packet size, and TCP flags 2. Logging System Create a logging mechanism that stores each packet's details in a file (network_events.log ) with a timestamp. Log entries should include: Timestamp Protocol (Ethernet, IP, TCP, UDP) Source and destination addresses Packet size 3. Throughput Calculation Throughput measures the amount of data processed over a time interval, typically expressed in bits per second (bps). Data Collection: Track the total bytes of tra8ic per protocol (Ethernet, TCP, UDP). Calculate the throughput by a set time interval (e.g.,10 seconds). Throughput Formula: For each protocol, calculate throughput as: o Throughput (bps)=(Total Bytes Captured *8)/(Time Interval) Display these throughput results periodically. 4. Latency Measurement Latency measures the time it takes for data to travel from the source to the destination. This project can approximate round-trip latency by observing timestamps for responses in TCP or UDP packets. Latency Tracking: For each TCP/UDP connection, capture the timestamp when a request packet is sent and the timestamp of the corresponding response packet. Store these timestamps in a dictionary, using unique identifiers for each connection. Latency Calculation: Calculate latency as the di8erence between the response and request timestamps: o Latency (ms)=(Response Timestamp - Request Timestamp)*1000 Average these values to get the overall latency for each protocol. A snippet of a code that calculates throughput and latency, adjust as you see fit to work in your code: throughput_data = defaultdict(int) latency_data ={} exit_flag = threading.Event() def update_event_data(protocol, src_addr, dest_addr, message_size, timestamp): event_data[protocol].append(message_size) throughput_data[protocol]+= message_size if protocol == "Ethernet": unique_macs.add(src_addr) else: unique_ips.add(src_addr) if protocol in ["TCP", "UDP"]: conn_key =(src_addr, dest_addr) if conn_key not in latency_data: latency_data[conn_key]={"start": timestamp} else: latency_data[conn_key]["end"]= timestamp def calculate_throughput(interval=10): print("
--- Throughput (bps)---") for protocol, bytes_count in throughput_data.items(): throughput_bps =(bytes_count *8)/ interval print(f"{protocol}: {throughput_bps:.2f} bps") throughput_data[protocol]=0 def calculate_latency(): total_latency =0 count =0 for conn_key, times in latency_data.items(): if "start" in times and "end" in times: latency =(times["end"]- times["start"])*1000 total_latency += latency count +=1 avg_latency = total_latency / count if count >0 else 0 print(f"
Average Latency: {avg_latency:.2f} ms")5. Multi-Connection Management Implement a TCP server-client model to support multiple concurrent connections. Use threading to handle multiple connections, allowing realtime packet capture without interruption. 6. Network Metrics Calculation Track metrics such as the total number of connections, unique IP addresses, and unique MAC addresses. Calculate protocol-specific metrics, including: Average packet size Total packets captured per protocol Rate of new connections (connections over time) Display these metrics in real-time, updating every 30 seconds. 7. Real-Time Statistics Display and Analysis Display summarized statistics in real-time on the console. Every 30 seconds, print an overview including: Number of connections per protocol Average packet size per protocol Number of unique IP and MAC addresses 8. Results Visualization Using matplotlib use the data in network_events.log and the results that youve got from calculating throughput and latency and produce these three graphs:1Throughput Over Time: Create a line

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!