有没有类似于 iwevent 的命令来监控 eth0 状态? [英] Is there a command similar to iwevent to monitor eth0 state?

查看:65
本文介绍了有没有类似于 iwevent 的命令来监控 eth0 状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置我的计算机以在我加入或离开某些网络时运行某些命令(即:在工作时启动 Synergy;在家里的局域网上启动 ssh 以便我可以同步等...).

I want to setup my computer to run certain commands when I join or leave certain networks (ie: Start up Synergy when at work; Start up ssh when on the lan at home so I can sync, etc...).

我发现 iwevent 将事件输出到我可以观看的无线接口.但是,当 eth0 连接或断开连接时,我找不到等效的观察.我试过ip monitor,但输出的数据太多,我无法理智地使用它.

I found iwevent which outputs events to the wireless interface that I can watch. However I can't find an equivalent to watch when eth0 is connected or disconnected. I tried ip monitor but there's so much data outputted I can't make use of it sanely.

有什么命令可以用来监控 eth0 的状态变化吗?Python 可用的 API 也可以使用.

Is there any command I can use to monitor state changes to eth0? An API available to Python works too.

推荐答案

也看看/sys/class/net/下的文件

Also take a look at files under /sys/class/net/

对于 eth0 子目录/sys/class/net/eth0/文件:

for eth0 subdirectory /sys/class/net/eth0/ files:

运营商、休眠、运营状态

根据链接条件变化:

if up + cable:carrier=1,dormant=0,operstate=up

if up + cable: carrier=1, dormant=0, operstate=up

if up + NO cable:carrier=0,dormant=0,operstate=down

if up + NO cable: carrier=0, dormant=0, operstate=down

if down + cable: catcarrier=Invalid argument, cat dormant=Invalid argument, operstate=down

if down + cable: cat carrier=Invalid argument, cat dormant=Invalid argument, operstate=down

这篇关于有没有类似于 iwevent 的命令来监控 eth0 状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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