poe_network_status.py

Xerxes Nano Carrier Board for Jetson Orin Nano Super and Turing RK1 Modules · File : poe_network_status.py · Language : Python · Use case : Surveillance de l'état du lien réseau Gigabit Ethernet alimenté par PoE.

Python script checking Ethernet link integrity and IP address, useful for confirming PoE power stability and network connectivity.

Hardware: Ethernet cable connected to Xerxes Nano RJ45 (PoE) port. Software: Python 3, network utilities (ethtool, iproute2). Execution: python3 poe_status.py. Ensure the PoE switch or injector provides sufficient power.

poe_network_status.py

#!/usr/bin/env python3
import subprocess
import json
import time

INTERFACE = 'eth0' # Interface principale Ethernet sur Xerxes Nano

def get_network_status(iface):
    try:
        # Utilisation de ethtool pour vérifier le lien et la vitesse
        result = subprocess.run(['ethtool', iface], capture_output=True, text=True)
        if 'Link detected: yes' in result.stdout:
            print(f"[{time.strftime('%H:%M:%S')}] {iface}: Lien actif")
            # Extraction de la vitesse
            for line in result.stdout.split('\n'):
                if 'Speed:' in line:
                    print(f"   Vitesse: {line.split(':')[1].strip()}")
        else:
            print(f"[{time.strftime('%H:%M:%S')}] {iface}: Lien inactif")
            
        # Vérification de l'adresse IP via ip command
        ip_result = subprocess.run(['ip', '-4', 'addr', 'show', iface], capture_output=True, text=True)
        if 'inet' in ip_result.stdout:
            ip_addr = ip_result.stdout.split('inet')[1].split()[0]
            print(f"   IP: {ip_addr}")
            
    except Exception as e:
        print(f"Erreur: {e}")

if __name__ == '__main__':
    print("Surveillance du port Ethernet PoE de la Xerxes Nano...")
    while True:
        get_network_status(INTERFACE)
        time.sleep(10)

← Back to the board