determine if connection is wired or wireless?

余生颓废 提交于 2019-12-07 02:53:32

Try this:

tail -n+3 /proc/net/wireless | grep -q . && echo "We are wireless"

Details

On a hardwired system, the contents of /proc/net/wireless consist of two header lines:

# cat /proc/net/wireless 
Inter-| sta-|   Quality        |   Discarded packets               | Missed | WE
 face | tus | link level noise |  nwid  crypt   frag  retry   misc | beacon | 22

On a system with an active wireless interface, there will be a third line displaying data about that interface.

The command above works as follows

  • The tail -n+3 command is used to remove the header.

  • The grep -q . command tests for the presence of subsequent lines that are present if a wireless interface is active.

Alternative

iwconfig is a utility that reads information from /proc/net/wireless:

iwconfig 2>&1 | grep -q ESSID && echo "We are wireless"
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!