Site Tools


toggle_radio

This is an old revision of the document!


Turning on/off WiFi radio elements from a script

Full Wireless operation

If you want to enable/disable WiFi from the command line you can use the following system commands:


Toggle:


/sbin/radio toggle



Force radio off:


/sbin/radio off



Force radio on:


/sbin/radio on

Wireless chipset (2.4/5GHz) specific operation

Modern routers come with 2 or more chipsets WiFi interfaces. There is usually one 2.4GHz interface and one or more 5GHz interfaces. In certain case you might want to enable/disable a specific chipset via the command line.

Once you've identified the name of the appropriate radio interface (via the Virtual Wireless page):




Do not blindly use this table. Your router's interface names might be different. For full chipset operation, refer to the “ethX” name reference of the interface. Once you have the correct name, you can check the status of your WiFi interface as follows:


For example, using “eth1” in my the above example:

Verify interface state


int=eth1
[ $(wl -i $int radio | grep -Eo [0-1]$) -eq 1 ] && echo “radio $int is off” || echo “radio $int is on”



Toggle interface state


int=eth1
[ $(wl -i $int radio | grep -Eo [0-1]$) -eq 1 ] && wl -i $int radio on || wl -i $int radio off



Force interface off


int=eth1
wl -i $int radio off



Force interface on



int=eth1
wl -i $int radio on

Wireless SSID-specific operation

In some cases, you don't want to adjust the radio chipset, just restrict access to only one specific SSID. This can be achieved as follows:

- Identify the SSID virtual interface you want to control.

Remember: virtual interfaces are always defined as [ main wireless interface name ] + [.] + [number 0-3]

so e.g. “wl0.1”. The full list of wireless interfaces available on your router and the all their sub-interfaces once again can be found under Virtual Wireless

For example:





Now let's assume you want to turn off wl1.3 which is associated to SSID “test”



Now, we can perform the following:

Toggle

int=wl1.3
[ $(wl -i $int radio | grep -Eo [0-1]$) -eq 1 ] && wl -i $int radio on || wl -i $int radio off



Force Off



int=wl1.3
wl -i $int radio off



Force On



int=wl1.3
wl -i $int radio on

Wireless SSID specific operation

Let's say, as it often happens), a specific SSID you have defined is operational on multiple interfaces/sub-interfaces, you can disable the SSID everywhere as follow:

Force Off
SSID=MYCOOLSSID
nvram show | grep ssid | grep $SSID | while read line; do wl -i $(echo $line | cut -d“=” -f1 | cut -d_ -f1 ) radio off; done

Force On
SSID=MYCOOLSSID
nvram show | grep ssid | grep $SSID | while read line; do wl -i $(echo $line | cut -d“=” -f1 | cut -d_ -f1 ) radio on; done

toggle_radio.1691353927.txt.gz · Last modified: 2023/08/06 21:32 by hogwild