How to find speed of WLAN interface?
Solution 1
You can use the iwconfig
tool to find this info out:
$ iwconfig wlan0
wlan0 IEEE 802.11bg ESSID:"SECRETSSID"
Mode:Managed Frequency:2.462 GHz Access Point: 00:10:7A:93:AE:BF
Bit Rate=48 Mb/s Tx-Power=14 dBm
Retry long limit:7 RTS thr:off Fragment thr:off
Power Management:off
Link Quality=55/70 Signal level=-55 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
If you want the bit rate from /sys
, directly try this:
$ cat /sys/class/net/wlan0/wireless/link
51
Or from /proc
:
$ cat /proc/net/wireless
Inter-| sta-| Quality | Discarded packets | Missed | WE
face | tus | link level noise | nwid crypt frag retry misc | beacon | 22
wlan0: 0000 56. -54. -256 0 0 0 0 0 0
NOTE: The value for the link in the 2nd example is 56, for e.g.
I believe the MB/s is a calculated value, so it won't be stored anywhere specifically for the wlan0 device. I think it's taking the aggregate bits transferred over the interface and dividing it by the time it took said data to be transferred.
One additional way to get this information is using the tool iw
. This tool is a nl80211 based CLI configuration utility for wireless devices. It should be on any recent Linux distro.
$ iw dev wlan0 link
Connected to 00:10:7A:93:AE:BF (on wlan0)
SSID: SECRETSSID
freq: 2462
RX: 89045514 bytes (194863 packets)
TX: 34783321 bytes (164504 packets)
signal: -54 dBm
tx bitrate: 48.0 MBit/s
This also shows the amount of sent and received packets (RX/TX).
Solution 2
The approach by slm is wrong, the data rate shown by iwconfig
is the max speed supported by the interface for the link. It's not the current at which data is transferred. Use the /sys/class/net/<interfacename>/statistics/<tx/rx>_bytes
file to get per interface bytes transferred live.
Solution 3
The short answer is "no", there is still no proper sysfs interface for WiFi in Linux. [Last checked: Linux 5.10]. But that doesn't mean you're out of luck. The information is exposed to the user through a C API called "nl80211", so all you need is a program which can extract the information you want. I recommend wavemon
which has a curses interface which shows information in realtime:
┌─Interface──────────────────────────────────────────────────────────────────────────────────────────────────┐
│wlan0 (IEEE 802.11), phy 0, reg: n/a, SSID: Fifi's HiFi WiFi │
├─Levels─────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ │
│link quality: 54% (38/70) │
│========================================================== │
│ │
│ │
│signal level: -72 dBm (0.06 nW) │
│================================= │
│ │
├─Statistics─────────────────────────────────────────────────────────────────────────────────────────────────┤
│RX: 80k (53.26 MiB), drop: 12 (0.0%) │
│TX: 88k (31.45 MiB), retries: 8k (9.7%) │
├─Info───────────────────────────────────────────────────────────────────────────────────────────────────────┤
│mode: Managed, connected to: 74:DA:88:42:CA:FE, time: 27:45m, inactive: 0.0s │
│freq: 5785 MHz, ctr1: 5775 MHz, channel: 157 (width: 80 MHz) │
│rx rate: 234.0 Mbit/s VHT-MCS 5 80MHz VHT-NSS 1, tx rate: 260.0 Mbit/s VHT-MCS 3 80MHz short GI VHT-NSS 2 │
│beacons: 16020, lost: 298, avg sig: -69 dBm, interval: 0.1s, DTIM: 1 │
│power mgt: on, tx-power: 22 dBm (158.49 mW) │
│retry: short limit 7, rts/cts: off, frag: off │
├─Network────────────────────────────────────────────────────────────────────────────────────────────────────┤
│wlan0 (UP RUNNING BROADCAST MULTICAST) │
│mac: 34:C9:3D:CC:DD:EE, qlen: 1000 │
│ip: 192.168.9.167/24 │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
F1 info F2 lhist F3 scan F7 prefs F8 help F9 about F10 quit
That's a lot of data, but if you examine the Info section you'll find what you're looking for:
tx rate: 260.0 Mbit/s VHT-MCS 3 80MHz short GI VHT-NSS 2
That's the wireless connection rate of the MAC layer, which is exactly what /sys/class/net/wlan0/speed
¹ ought to show.
¹ Okay, technically, it ought to be speedtx
and speedrx
since WiFi is asymmetrical.
Related videos on Youtube
Tural Gurbanov
Updated on September 18, 2022Comments
-
Tural Gurbanov over 1 year
I'm trying to find the speed of a network interface using a file descriptor. It's easy to do it for
ethX
, just callingcat /sys/class/net/eth0/speed
. Unfortunately, this method doesn't work with wireless interfaces. When I call/sys/class/net/wlan0/speed
I get an error: invalid argument.So, do you know any
/sys/class/net/eth0/speed
like analog for WLAN interfaces? -
Tural Gurbanov almost 11 yearsThe application, for which I look a solution, uses file-like object to read network speed from it. And I can't add any new part of code that may help me extract information from iwconfig. The config for application uses only path to file with speed.
-
slm almost 11 yearsDo you not have iwconfig already installed? It's typically installed if you have a wireless network. I've yet to have to explicitly install it on any systems I've encountered that have wireless.
-
phiresky almost 6 yearsNote that you might get more information from
iwconfig
when running it as root. Speed, dBm etc is missing for me without root -
Architector 4 almost 3 yearsConsidering that the question's body mentions them trying
/sys/class/net/<interfacename>/speed
, which is also the maximum link speed, I'd imagine that other answer is exactly what they want.