network-monitor-eth.py

AAEON PICO-PTH4 : Carte Pico-ITX avec SoC Intel Panther Lake · Fichier : network-monitor-eth.py · Langage : Python · Usage : Surveiller le trafic réseau sur les ports Ethernet 2.5GbE Intel I226.

Script de monitoring réseau utilisant psutil pour afficher les statistiques de trafic sur les interfaces Ethernet 2.5GbE.

La carte possède deux ports Intel I226 2.5GbE. Installez psutil (pip install psutil). Vérifiez les noms d'interfaces avec 'ip link'. Les drivers Linux natifs supportent l'I226. Exécution : python3 net_monitor.py. Utile pour valider la bande passante.

network-monitor-eth.py

import socket
import time
import psutil

def monitor_network():
    # Nom de l'interface (à vérifier avec 'ip a')
    interface = 'eth0'
    print(f"Surveillance de l'interface {interface}...")
    
    try:
        while True:
            counters = psutil.net_io_counters(pernic=True)
            if interface in counters:
                stats = counters[interface]
                # Calcul du débit en Mbps (approximatif)
                bytes_sent = stats.bytes_sent
                bytes_recv = stats.bytes_recv
                
                print(f"[{time.strftime('%H:%M:%S')}] TX: {bytes_sent/1024/1024:.2f} MB | RX: {bytes_recv/1024/1024:.2f} MB")
            else:
                print(f"Interface {interface} non trouvée. Vérifiez le nom.")
                break
            time.sleep(5)
    except KeyboardInterrupt:
        print("Arrêt de la surveillance.")

if __name__ == "__main__":
    monitor_network()

← Retour à la fiche