A small shell script that uses vnstat to check the total network usage per day and change the MAC address if the usage exceeds the set amount
What it does is check if the network usage has exceeded the set limit by getting daily data from vnstat. If it has exceeded it changes the MAC address by increasing the last two digit in the MAC address by one. If this number goes over 50, it jumps down to 10 and starts over and so forth.
- Vnstat must be installed and running
- OpenWRT based router
- Download the script and place it where you want (eg. /bin/checkusage.sh).
- Edit the file and configure (See below for configuration details).
- Chmod a+x to make the script executable.
- Add the script to crontab to check as often as you like.
Place the script under /usr/bin/checkusage so that you can run it without having the specify the path
To add the script to check once a day simply type "crontab -e" and add the line "0 11 * * * /bin/checkusage.sh* to use the script at 11 o'clock each day. Remember to restart cron by typing "/etc/init.d/cron restart"
Since version 1.1.x checkusage now makes a file with the date of the last change, so the script can now be run more frequent without it changing the mac each time it checks. So a crontab could look like "*/15 * * * * checkusage" to run it every 15th minute.
- LIMIT is the limit you don't want your network usage to exceed. Based on LIMITSTR for unit.
- LIMISTR is the unit of which the limit should be in (eg. GiB, MiB, KiB).
- PREFIX is the 5 first numbers of the MAC address you want to use. The last two will be automatically generated if the usage exceeds the limit.
- INTERFACE is the interface your router uses to connect to internet (wan) (eg. eth0, eth1 etc).
- Use force command to force a MAC change. (eg. /bin/checkusage.sh force)
- WNDR3700 running OpenWRT 10.03.1-RC3
I am not responsible for any damage done by this script, although it should be harmless in theory. I cannot promise that it will work on your device, but I would be happy to know if it did.