import random
import time
def generate_packet():
"""Simulate generating a network packet."""
source_ip = f"192.168.1.{random.randint(1, 254)}"
dest_ip = f"192.168.1.{random.randint(1, 254)}"
protocol = random.choice(['TCP', 'UDP', 'ICMP'])
return {
'source': source_ip,
'destination': dest_ip,
'protocol': protocol
}
def display_packet(packet):
"""Display packet information."""
print(f"Packet captured: {packet['protocol']} | Source: {packet['source']} | Destination: {packet['destination']}")
def main():
print("Network Sniffer Simulator")
print("Capturing packets... (Press Ctrl+C to stop)")
try:
while True:
packet = generate_packet()
display_packet(packet)
time.sleep(1) # Simulate delay between packet captures
except KeyboardInterrupt:
print("\nStopped packet capture.")
if __name__ == "__main__":
main()