network-monitoring-25gbe.py

AAEON PICO-PTH4: Placa Pico-ITX con SoC Intel Panther Lake · Archivo : network-monitoring-25gbe.py · Lenguaje : Python · Uso : Surveillance du trafic réseau sur les interfaces Ethernet 2.5GbE Intel I226

Monitor de tráfico de red en tiempo real para los dos puertos Ethernet 2.5GbE integrados en la placa.

Instale 'psutil'. La placa tiene dos puertos Intel I226 2.5GbE. Identifique los nombres de interfaces con 'ip link'. Este script calcula las tasas Tx/Rx por segundo.

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'.")

← Volver a la ficha