0

I want to promatically set channel of WiFI card with shell script. Currently, I have the following script:

  • /etc/network/interfaces

    # tell wlan0 will be controlled manually
    iface wlan0 inet manual
    
  • setup.sh

    iw dev wlan0 interface add mon0 type monitor
    # wait until mon0 is successfully created
    ip link show mon0 2>/dev/null 1>/dev/null
    while [ $? -ne 0 ]
    do
            ip link show mon0 2>/dev/null 1>/dev/null
    done
    
    ifconfig mon0 up
    # wait until mon0 is activated
    ifconfig mon0 2>/dev/null 1>/dev/null
    while [ $? -ne 0 ]
    do
            ifconfig mon0 2>/dev/null 1>/dev/null
    done
    
    iw mon0 set channel 1 HT20
    

And then, I can set channel of WiFI card by typing [sudo] ./setup.sh

However, I wonder if there is a way to wait until WiFi card actually sets its channel to 1 by the last command iw mon0 set channel ....

i.e., in pseudocode

iw mon0 set channel 1 HT20
channel = get_wifi_current_channel
while [ "$channel"-ne 1 ]
do
    ;
done

and I am looking for a proper one of get_wifi_current_channel

One thing I have found is iwconfig mon0:

$ iwconfig mon0
mon0    IEEE 802.11bgn  Mode:Monitor  Frequency:2.412 GHz  Tx-Power=15 dBm
...

If there is nothing for get_wifi_current_channel, I can make a script or a program manipulating the output of iwconfig mon0.

Your Answer

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

Browse other questions tagged or ask your own question.