linux -/proc/net/wireless 中的 "Status"字段

标签 linux bash networking

我正在尝试使用 bash 脚本检查是否有任何无线接口(interface)处于 UP 状态。我想我可以通过检查每个接口(interface)的/proc/net/wireless 中的 Status 字段来做到这一点。但是,我试图查找该字段中可能的值及其含义的引用,但似乎没有任何结果。有人知道吗?这是解决这个问题的理想方法吗?

最佳答案

您需要检查每个接口(interface)的 operstate 以判断它是否是;向上、向下或未知。下面是使用 GNU awk 的一种方法:

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

在我的系统上,这里有一些结果:

eth0: up
lo: unknown
vboxnet0: down
wlan0: up

要仅检查无线接口(interface),您需要在每个接口(interface)下检查名为“wireless”的文件夹。这是使用 GNU awk 的一种方法。

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)

结果:

wlan0

伪代码:

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.

关于linux -/proc/net/wireless 中的 "Status"字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12791608/

相关文章:

c - 如何在PAM应用程序中捕获密码

mysql - 将 mysqldump 从 bash 脚本重定向到文件

mysql - 精确时间之间的查询

python-3.x - 基本 UDP 网络不接收

linux - 创建一个 Linux 数据包拆分器

C++ ofstream 写入在 Windows 下不起作用。在 Linux 下工作正常

arrays - bash 中的关联数组用于存储所有以 X 开头的行

linux - 从文件 bash shell 脚本中获取数据

linux - 使用 bash 脚本打开最新下载的文件

c++ - 高频接收UDP包 : packet loss?