关闭

判断网线是否插入电脑

887人阅读 评论(0) 收藏 举报

工具 ethtool


如果没有安装,则sudo apt-get install ethtool


终端运行 sudo ethtool eth0

结果1:(网线插入时)

p { margin-bottom: 0.08in; }

Supported ports: [ TP MII ]

Supported link modes: 10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

1000baseT/Half 1000baseT/Full

Supports auto-negotiation: Yes

Advertised link modes: 10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

1000baseT/Half 1000baseT/Full

Advertised pause frame use: No

Advertised auto-negotiation: Yes

Link partner advertised link modes: 10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

Link partner advertised pause frame use: No

Link partner advertised auto-negotiation: Yes

Speed: 100Mb/s

Duplex: Full

Port: MII

PHYAD: 0

Transceiver: internal

Auto-negotiation: on

Supports Wake-on: pumbg

Wake-on: g

Current message level: 0x00000033 (51)

Link detected: yes


结果2(网线拔除时):

p { margin-bottom: 0.08in; }

Supported ports: [ TP MII ]

Supported link modes: 10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

1000baseT/Half 1000baseT/Full

Supports auto-negotiation: Yes

Advertised link modes: 10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

1000baseT/Half 1000baseT/Full

Advertised pause frame use: No

Advertised auto-negotiation: Yes

Link partner advertised link modes: Not reported

Link partner advertised pause frame use: No

Link partner advertised auto-negotiation: No

Speed: 10Mb/s

Duplex: Half

Port: MII

PHYAD: 0

Transceiver: internal

Auto-negotiation: on

Supports Wake-on: pumbg

Wake-on: g

Current message level: 0x00000033 (51)

Link detected: no


可见可以根据grep"link detected: yes"的结果来判断是否插入网线



shell 中写下列代码

ethtool eth0 | grep "Link detected: yes"
判断一下上面这条命令的输出就可以知道网线是不是接上了
if  上面的输出为空, 那么网线就是没有接上的
else 网线连接正常。



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:90954次
    • 积分:1240
    • 等级:
    • 排名:千里之外
    • 原创:33篇
    • 转载:18篇
    • 译文:1篇
    • 评论:10条
    最新评论