Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

nmcli: Proper way of scanning WiFi networks

Writer Emily Wong

I am writing a script where I need to switch WiFi networks. How should I scan if the WiFi I want to connect is available or not?

I tried the following:

  1. nmcli dev wifi list

    Issue: It lists previously scanned networks, which includes available and non-available networks.

  2. nmcli dev wifi rescan; sleep 10; nmcli dev wifi list;

    Issue 1: It just starts the scan and exits while the scan is running in the background. I could not find how to detect if the scan is finished or not. So I used added waiting time of 10 seconds.

    Issue 2: Even after the scan is finished (After 10 seconds), it is still listing the recently turned off WiFi networks.

  3. nmcli radio wifi off ; sleep 1; nmcli radio wifi on; sleep 4; nmcli dev wifi list

    This one is the worst unexpected. It still shows the WiFi networks which are turned off.

Running the commands as root does not make any difference.

What is wrong with the nmcli? What am I doing wrong?

System information:

OS: Ubuntu 20.04 Desktop.
Driver: Kernel driver in use: rtl8821ce
Laptop: hp 15 dy1751ms
WiFi product: RTL8821CE 802.11ac PCIe Wireless Network Adapter vendor: Realtek Semiconductor Co., Ltd. physical id: 0 bus info: pci@0000:01:00.0 logical name: wlo1 serial: xx:xx:xx:xx:xx:xx width: 64 bits clock: 33MHz capabilities: bus_master cap_list ethernet physical wireless configuration: broadcast=yes driver=rtl8821ce ip=192.168.10.12 latency=0 multicast=yes wireless=IEEE 802.11bgn resources: irq:137 ioport:3000(size=256) memory:8050000-8050ffff
5 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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