Linux узнать какие wifi

Get Wi-Fi interface device names

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:

9 Answers 9

With nmcli you could list all devices and their type e.g.

nmcli --get-values GENERAL.DEVICE,GENERAL.TYPE device show
eno1 ethernet wlp1s0 wifi wlp1s1 wifi p2p-dev-wlp1s0 wifi-p2p lo loopback 

Per the manual, when using -g, —get-values , the «output is terse. This mode is designed and suitable for computer (script) processing». So you can pipe that output to other tools and get the wifi devices names e.g.

On linux you also 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. 
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 

To extract only interfaces names you could process the output e.g.

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.

The ‘Do NOT screenscrape’ comment only seems to appear when help is shown, due to invalid input or an explicit help command, but not in the output of valid results.

Just a reminder that you may need to run this as root i.e. sudo iw dev , because running it as a non-privileged user may return no results.

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.

Universal way (non root) tested on Android 4, Android 7.1 and Android 9 and ArchLinux.

ls /sys/class/ieee80211/*/device/net/ 

Great answer. To dump only relevant info, ls /sys/class/ieee80211/*/device/net/* -d | sed -E ‘s|^.*(phy[^/]+)/.*/|\1 |’

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 
for dev in `ls /sys/class/net`; do [ -d "/sys/class/net/$dev/wireless" ] && echo "$dev" 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

Читайте также:  What is fastest linux distro

Even though sysfs probably has sane file names, parsing the output of ls is bad practice and a common pit fall in bash.

I like the find solution too; it only finds files that actually exist which solves the awkward * that other solutions here get. I found that I needed a slightly different set of parameters to reduce the amount of noise cause by file system loops. The following works nicely for me, but does spawn an extra subshell for cut and relies on assumptions about indexes: find -H /sys/class/net/* -name wireless | cut -d / -f 5 Furthermore I needed an additional | head -n1 for my particular use-case.

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

# find the directories $ printf '%s\n' /sys/class/net/*/wireless # substitute with phy80211 if desired /sys/class/net/wlp4s0/wireless # filter out the "device" part $ printf '%s\n' /sys/class/net/*/wireless | cut -d/ -f5 wlp4s0 

Note that this will still print * if no wireless device exists, instead of an empty result. Instead, try this with only POSIX shell built-ins: printf ‘%s\n’ /sys/class/net/*/wireless | while IFS=’/’ read -r -a p;do [ -e «/sys/class/net/$» ] && echo «$»;done .

@Yeti posix-sh doesn’t have arrays though? As for printing the glob versus an empty result, I think (at least for some shells) that depends on nullglob.

Why not just filter the unwanted * out: printf ‘%s\n’ /sys/class/net/*/wirelessREMOVETHIS | cut -d / -f 5 | grep -v ‘*’

@StephanHenningsen good use of cut instead of awk, edited. I’m not convinced on the * part though; I really think it depends on what you’re doing, what the shell options are, and whether or not your device might have an asterisk in it (shudders)

Here’s a simple and very effective loop that answers the question:

for dev in /sys/class/net/*; do [ -e "$dev"/wireless ] && echo $ done 

This one picks the first wireless interface and stores it in $iwdev , which was what I needed:

for dev in /sys/class/net/*; do if [ -e "$dev"/wireless ]; then iwdev=$; break; fi done 

It’s a rewrite of Josh’s answer which I found nice and simple. The above approach handles spaces and other oddities in file names. It also doesn’t make too many assumptions about file paths being sane and relies on a minimum of slashes and indexing. Finally it uses built-in parameter expansion for extracting the base device name instead of spawning a subshell for cut or awk .

Источник

How to find out which Wi-Fi driver is installed?

In other words, the /sys hierarchy for the device ( /sys/class/net/$interface/device ) contains a symbolic link to the /sys hierarchy for the driver. There you’ll also find a symbolic link to the /sys hierarchy for the module, if applicable. This applies to most devices, not just wireless interfaces.

Читайте также:  Astra linux универсальная операционная система

Maybe there’s a better way, but I’ve used lshw -class network (as root) and it gives me this output:

 *-network description: Ethernet interface product: 82566MM Gigabit Network Connection vendor: Intel Corporation physical id: 19 bus info: pci@0000:00:19.0 logical name: eth0 version: 03 serial: 00:a0:d1:a3:87:c8 size: 1GB/s capacity: 1GB/s width: 32 bits clock: 33MHz capabilities: pm msi bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation configuration: autonegotiation=on broadcast=yes driver=e1000e driverversion=1.0.2-k2 duplex=full firmware=0.3-0 ip=192.168.2.206 latency=0 link=yes multicast=yes port=twisted pair speed=1GB/s resources: irq:29 memory:fc300000-fc31ffff memory:fc325000-fc325fff ioport:1840(size=32) *-network description: Wireless interface product: PRO/Wireless 4965 AG or AGN [Kedron] Network Connection vendor: Intel Corporation physical id: 0 bus info: pci@0000:06:00.0 logical name: wlan0 version: 61 serial: 00:1d:e0:69:28:07 width: 64 bits clock: 33MHz capabilities: pm msi pciexpress bus_master cap_list ethernet physical wireless configuration: broadcast=yes driver=iwlagn ip=192.168.0.104 latency=0 multicast=yes wireless=IEEE 802.11abgn resources: irq:31 memory:c8000000-c8001fff *-network DISABLED description: Ethernet interface physical id: 3 logical name: vboxnet0 serial: 0a:00:27:00:00:00 capabilities: ethernet physical configuration: broadcast=yes multicast=yes 

You can grep for driver from that output. In my case I use lsmod | grep iwlagn , giving me:

iwlagn 63559 0 iwlcore 67702 1 iwlagn mac80211 123574 2 iwlagn,iwlcore cfg80211 87657 3 iwlagn,iwlcore,mac80211 

Don’t ask me what each of those mean 🙂

Источник

How can I display the list of available Wi-Fi networks?

My Ubuntu laptop’s Wi-Fi works fine on various Wi-Fi networks. But the list of available networks accessed from the toolbar icon of nm-applet no longer appears. I just see the known networks. The list of hidden networks also doesn’t show any new networks. sudo iwlist scan likewise only shows known networks. How do I get a list of all available networks so I can connect to one? I am using Xubuntu 14.04.

Does terminal command nmcli dev wifi list give anything additional to what’s shown by the GUI applet?

Also worth noting that sudo iwlist scan shows more available networks than iwlist scan (without sudo ) — so this question by itself is helpful. But perhaps it should be renamed to «How can I display the list of hidden WiFi networks»?

4 Answers 4

Use the nmcli dev wifi command. It shows transfer rate, signal strength, and security (e.g. WPA) as well:

screenshot after running

For more, see nmcli ‘s manual and this for usage examples of nmcli .

Here is the pertaining mnemonic: network manager command line interface device wifi

The BSSID (MAC of remote access point) and other details are not shown by default, but you can show them with the -f option, e.g. nmcli -f SSID,BSSID,DEVICE dev wifi . Use -f ALL to see available fields.

Читайте также:  Linux update package rpm

@icc97 — if you only see your current network, run nmcli dev wifi rescan , wait a bit, and then try nmcli dev wifi again.

To scan all networks try using the command sudo iw dev wlan0 scan | grep SSID .

wlan0 should be replaced with real value from ifconfig of from /sys/class/net subfolder name, as stated in answer from @gujarat santana

This works better than nmcli for me because it breaks down and shows non-latin characters, where nmcli just shows a «?»

@EkriirkE well, for a more detailed breakdown on wifi networks in nmcli command you could use -f ALL option, e.g. nmcli -f ALL dev wifi . Although I admit, it’s still not as detailed as iw ‘s information.

@EkriirkE sorry, I probably misread your comment. You stated that it worked better for you since «it breaks down», and I thought you meant «breaking down» as in «showing detailed information». With that said, I am not sure who are «we» ☺ I definitely wanted the technical details on the networks, and the question or the answer don’t seem to limit the question to just SSIDs.

  1. Go to /sys/class/net you can see list of directories here.
  2. Find the wireless interface. It has wireless directories, for example in my case it’s wlp10 . You can check it using ls wlp10 . If the directory’s name different, use that directory’s name.
  3. sudo iwlist wlp1s0 scan | grep ESSID

From here you can list all available Wi-Fi access points.

Further to what has been already answered here, I’ve merged a few of them and added a little flavor of my own.

As for the nmcli answer, sure, do that if you want to install more software. But if you’re looking for Access Points, maybe you don’t have an internet connection yet and are unable to connect to install said software. With all that said, here’s my solution:

for i in $(ls /sys/class/net/ | egrep -v ^lo$); do sudo iw dev $i scan | grep SSID | awk ''; done 2>/dev/null | sort -u 
for i in $(ls /sys/class/net/ | egrep -v ^lo$); 

Lets have a look at all the contents of the location /sys/class/net. This will list all the network devices, but we’re not really interested in the loopback interface. so we’ll ignore that one

do sudo iw dev $i scan | grep SSID | awk '';done 

For each of the network interfaces we found above, lets do the scan to list all the SSIDs (and only the SSIDs)

And ignore all the errors (like searching for SSIDs with ethernet interfaces).

And finally, If you have multiple wi-fi adapters on the system, only list each SSID once.

Источник

Оцените статью
Adblock
detector