如何检测网络电缆/连接器的物理连接状态? [英] How to detect the physical connected state of a network cable/connector?

查看:185
本文介绍了如何检测网络电缆/连接器的物理连接状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux环境中,我需要检测RJ45连接器到其插座的物理连接或断开状态。最好只使用BASH脚本。

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 following solutions which have been proposed on other sites do NOT work for this purpose:


  1. 使用ifconfig - 因为网络电缆可能已连接,但网络未正确配置或当前未正常启动。

  2. Ping主机 - 产品将在使用未知网络配置和未知主机的LAN内。

不存在可用于/ proc文件系统(一切都在那里)?

Isn't there some state which can be used in the /proc file system (everything else is in there)?

Linux世界如何有自己的版本的Windows泡沫从图标托盘

How is the Linux world suppose to have their own version of the Windows bubble that pop up from the icon tray indicating that you've just unplugged the network cable?

Kent Fredric lothar ,你的答案都满足我的需要...非常感谢!我将使用哪一个...我还是不知道。

Kent Fredric and lothar, both of your answers satisfy my need... thanks a lot! Which one I'll use... I still don't know.

我想我不能把你都当作正确答案吗?它可能是公平的,为你,我选择一个。翻转硬币我猜?

I guess I can't put you both down as the correct answer? And its probably fair for you that I do choose one. Flip a coin I guess? Again, thanks!

推荐答案

您要查看


/sys/class/net/

我试验了我的:

电线插入:

eth0/carrier:1
eth0/operstate:unknown

电线删除:

eth0/carrier:0
eth0/operstate:down

再次插入:

eth0/operstate:up
eth0/carrier:1

侧面招式:以简单的方式立即收获所有属性:

grep "" eth0/* 


b $ b

这会形成一个很好的 key:value 对列表。

这篇关于如何检测网络电缆/连接器的物理连接状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆