16

Similar to a previous question about finding network device names, I would like to get a (reliable) list of device names but just for Wi-Fi devices. So that it looks like the following depending on your naming structure:

wlan0
wlan1

or

wlp5s0
wlp5s1
13

On linux you have iw (show/manipulate wireless devices and their configuration) and when used with the dev command:

Commands:
    dev
        List all network interfaces for wireless hardware.

that is

iw dev

you'll get something like:

phy#0
    Interface wlan0
        ifindex 3
        wdev 0x1
        addr 00:12:32:e4:18:24
        type managed
phy#1
    Interface wlan1
        ifindex 4
        wdev 0x2
        addr 00:12:22:c6:b2:0a
        type managed

If you want to extract only interfaces names you can always process the output e.g.

iw dev | awk '$1=="Interface"{print $2}'

just keep in mind the help page clearly states:

Do NOT screenscrape this tool, we don't consider its output stable.
  • I like this answer, it solves the problem, but the bit about not scraping concerns me and makes me think there may be a better way. I'd like to leave this open for now. – Matt Copperwaite Jun 2 '16 at 16:51
8

On Ubuntu at least, there is the /proc/net/wireless file that contains details about the Wi-Fi interfaces. Which outputs for me:

$ cat /proc/net/wireless
Inter-| sta-|   Quality        |   Discarded packets               | Missed | WE
 face | tus | link level noise |  nwid  crypt   frag  retry   misc | beacon | 22
wlp5s0: 0000   36.  -74.  -256        0      0      0     16  33004        0

It's a little messy but the device name is in there.

To get just the interface name:

cat /proc/net/wireless | perl -ne '/(\w+):/ && print $1'

The perl code prints the string of word characters preceding the colon.

  • This did not work for me –probably because I have my wireless card disabled (but detectable). – imbuedHope Jan 17 '18 at 20:51
8

If you have sysfs mounted at /sys then the following commands work:

# find /sys/class/net -follow -maxdepth 2 -name wireless | cut -d / -f 5
wlan0
# find /sys/class/net -follow -maxdepth 2 -name phy80211 | cut -d / -f 5
wlan0

Or, without find:

for dev in `ls /sys/class/net`; do
  if [ -d "/sys/class/net/$dev/wireless" ]; then echo $dev; fi;
done

The first finds all devices in /sys/class/net with a wireless directory (which may be more than just WiFi devices) and the second finds devices that are 802.11 compatible

Tested on kernel 4.4

5

Building on Josh's answer, I'll use a shell glob to identify the /sys/class/net directories with a wireless directory inside, and awk to grab the device name:

# find the directories
$ echo /sys/class/net/*/wireless # substitute with phy80211 if desired
/sys/class/net/wlp4s0/wireless
# filter out the "device" part
$ echo /sys/class/net/*/wireless | awk -F'/' '{ print $5 }'
wlp4s0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.