Posted: Sun Mar 07, 2021 20:06 Post subject: Wifi client mode automatic MAC blocking script?
Hi, I have a ddwrt router setup in wifi client mode to connect to a group of APs (same SSID) in the surrounding area. The problem is, some APs are intermittently faulty. Currently, I manually add the bad APs to the MAC block list and it works. But these APs come and go, and the bad ones would work again after a while. I am trying to add a startup script to automatically ping 8.8.8.8 and if it fails, block the MAC address of the connected AP, until one that returns the ping. I want the blacklist to clear upon each reboot (I set reboot on a schedule). Can someone help or point me in the right direction? thanks
Pseudo code below:
Code:
Upon startup..
Clear Blacklist // optional if Blacklist saved to RAM only
Sleep 60
while AP connected {
ping -c 1 8.8.8.8
if successful then break/quit
else
block AP MAC // add to Blacklist
connect to next AP
Sleep 30
};
Since "wl mac" doesn't work with dd-wrt, I tested the following and it works to activate MAC Filter rule changes before nvram is committed.
Code:
nvram set wl0_maclist=*:*:*:*:*:*
restart radio_on
If nvram commit is undesirable, wl0_maclist can be cleared after "restart radio_on" executes, with the filters remaining in effect. I think this solves my problem, the rest of the code should be easy.
I managed to answer my own question, the following code successfully implements what I wanted (Save Startup on Command tab). Hope this helps someone. You may need to change wl1, eth2, and radio_on_1 to match your router's wifi interface parameters. The wl command also works differently on different routers. You should enable Mac Filter with Deny checked via Web GUI first, but leave the MAC list empty.
Code:
sleep 60
nvram set wl1_maclist=""
CurrentMAC="$(wl -i eth2 assoclist | head -n 1 | cut -c 11-27)"