Wifi client mode automatic MAC blocking script?

Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking
Author Message
fj123
DD-WRT Novice


Joined: 23 May 2016
Posts: 19

PostPosted: Sun Mar 07, 2021 20:06    Post subject: Wifi client mode automatic MAC blocking script? Reply with quote
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
};

Sponsor
fj123
DD-WRT Novice


Joined: 23 May 2016
Posts: 19

PostPosted: Wed Mar 10, 2021 4:34    Post subject: Reply with quote
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.
fj123
DD-WRT Novice


Joined: 23 May 2016
Posts: 19

PostPosted: Sat Mar 20, 2021 5:50    Post subject: Reply with quote
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)"

while [ ! -z $CurrentMAC ];do
 if ( ping -I eth2 -c 1 1.1.1.1 &> /dev/null && : || ping -I eth2 -c 1 8.8.8.8 &> /dev/null && : );then break;fi
 nvram set wl1_maclist="$(nvram get wl1_maclist) $CurrentMAC"
 restart radio_on_1
 sleep 60
 CurrentMAC="$(wl -i eth2 assoclist | head -n 1 | cut -c 11-27)"
done


Also add nvram set wl1_maclist="" to "Save Shutdown" if you don't want to commit nvram upon reboot.
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum