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

后端 未结 15 1400
隐瞒了意图╮
隐瞒了意图╮ 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条回答
  •  臣服心动
    2020-12-04 05:14

    Somehow if you want to check if the ethernet cable plugged in linux after the commend:" ifconfig eth0 down". I find a solution: use the ethtool tool.

    #ethtool -t eth0
    The test result is PASS
    The test extra info:
    Register test  (offline)         0
    Eeprom test    (offline)         0
    Interrupt test (offline)         0
    Loopback test  (offline)         0
    Link test   (on/offline)         0
    

    if cable is connected,link test is 0,otherwise is 1.

提交回复
热议问题