首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >/proc/net/wireless中的“状态”字段

/proc/net/wireless中的“状态”字段
EN

Stack Overflow用户
提问于 2012-10-09 01:18:39
回答 1查看 2.5K关注 0票数 1

我试图检查是否有任何无线接口与bash脚本。我想我可以通过为每个接口检查/proc/net/wireless中的状态字段来做到这一点。然而,我试图寻找该领域中可能存在的价值及其含义的参考,但似乎什么也没有出现。有人知道吗?这是解决这个问题的理想方法吗?

EN

回答 1

Stack Overflow用户

发布于 2012-10-09 02:06:12

您需要检查每个接口的operstate,以判断它是向上、向下还是未知。这里有一种使用GNU awk的方法

代码语言:javascript
复制
awk '{ split(FILENAME, array, "/"); print array[5] ": " $1 }' $(find /sys/class/net/*/operstate ! -type d)

在我的系统中,下面是一些结果:

代码语言:javascript
复制
eth0: up
lo: unknown
vboxnet0: down
wlan0: up

要只检查无线接口,您需要检查每个接口下的一个名为“无线”的文件夹。这里有一种使用GNU awk的方法。

代码语言:javascript
复制
awk -F "/" 'FNR==NR { wire[$5]++; next } { split(FILENAME, state, "/"); if (state[5] in wire && $1 == "up") print state[5] }' <(find /sys/class/net/*/wireless -type d) $(find /sys/class/net/*/operstate ! -type d)

结果:

代码语言:javascript
复制
wlan0

伪码:

代码语言:javascript
复制
1. Get the directory names of the wireless devices as the 1st argument
2. Split these names on the "/" delimiter
3. Add the 5th column (the name of the wireless device) to an array called 'wire'
4. Now read in the operstates of all network interfaces as the 2nd argument
5. Split the interface filenames on the "/" delimiter to an array called 'state'
6. If the interface is a wireless interface (i.e. if it's in the array called
   wire) and its operstate is "up", print it.
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12791608

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档