network-monitoring-25gbe.py
Real-time network traffic monitor for the two integrated 2.5GbE Ethernet ports on the board.
Install 'psutil'. The board has two Intel I226 2.5GbE ports. Identify interface names with 'ip link'. This script calculates Tx/Rx rates per second.
network-monitoring-25gbe.py
#!/usr/bin/env python3
"""
Surveillance réseau basique pour les interfaces Intel I226 2.5GbE.
Utilise 'psutil' pour lire les statistiques d'interface.
"""
import psutil
import time
# Identifier les interfaces réseau (souvent enp1s0, enp2s0)
# Utiliser 'ip addr' ou 'ifconfig' pour trouver les noms exacts
INTERFACES = ['enp1s0', 'enp2s0']
print("Surveillance du trafic réseau (Ctrl+C pour arrêter)...")
print(f"Interfaces surveillées: {INTERFACES}")
last_net_io = psutil.net_io_counters(pernic=True)
try:
while True:
current_net_io = psutil.net_io_counters(pernic=True)
for iface in INTERFACES:
if iface in current_net_io:
bytes_sent = current_net_io[iface].bytes_sent - last_net_io.get(iface, psutil.snic()).bytes_sent
bytes_recv = current_net_io[iface].bytes_recv - last_net_io.get(iface, psutil.snic()).bytes_recv
# Convertir en Mbps (approx)
mbps_sent = (bytes_sent * 8) / 1000000 / 1.0 # Par seconde
mbps_recv = (bytes_recv * 8) / 1000000 / 1.0
print(f"{iface}: Tx {mbps_sent:.2f} Mbps | Rx {mbps_recv:.2f} Mbps")
last_net_io = current_net_io
time.sleep(1)
print("-" * 30)
except KeyboardInterrupt:
print("\nArrêt de la surveillance.")
except Exception as e:
print(f"Erreur: {e}. Vérifiez les noms d'interfaces avec 'ip addr'.")