How to detect the physical connected state of a network cable/connector?

后端 未结 15 1405
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 04:23

In a Linux environment, I need to detect the physical connected or disconnected state of an RJ45 connector to its socket. Preferably using BASH scripting only.

The

15条回答
  •  猫巷女王i
    2020-12-04 05:01

    On OpenWRT the only way to reliably do this, at least for me, is by running these commands:

    # Get switch name
    swconfig list
    
    # assuming switch name is "switch0"
    swconfig dev switch0 show | grep link:
    
    # Possible output
    root@OpenWrt:~# swconfig dev switch0 show | grep link:
            link: port:0 link:up speed:1000baseT full-duplex txflow rxflow
            link: port:1 link:up speed:1000baseT full-duplex txflow rxflow eee100 eee1000 auto
            link: port:2 link:up speed:1000baseT full-duplex txflow rxflow eee100 eee1000 auto
            link: port:3 link:down
            link: port:4 link:up speed:1000baseT full-duplex eee100 eee1000 auto
            link: port:5 link:down
            link: port:6 link:up speed:1000baseT full-duplex txflow rxflow
    

    This will show either "link:down" or "link:up" on every port of your switch.

提交回复
热议问题