Last active
November 8, 2016 19:28
-
-
Save assertivist/91e8a5c224dc5357b82ad93df4d10185 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# list of MAC addresses, 1 per line | |
MACFILE="/jffs/etc/config/maclist" | |
# current mac address | |
current_mac=$( nvram get def_hwaddr ) | |
# get current MAC index from file | |
macindex=$( grep -n $current_mac $MACFILE | cut -f1 -d: ) | |
# if we didn't find a match, don't do anything | |
if [ -z $macindex ] ; then | |
exit | |
fi | |
# increment the index we have | |
macindex="$( expr $macindex + 1 )" | |
# get the length of our MAC file | |
file_length="$( wc -l $MACFILE | cut -f1 -d' ' )" | |
# wrap around if index is more than | |
# number of lines in MAC list file | |
if [ $macindex -gt $file_length ] ; then | |
macindex=1 | |
fi | |
# get new MAC from file | |
new_mac=$( sed -n ${macindex}p $MACFILE ) | |
#echo "New MAC: $new_mac" | |
# set new value in nvram | |
nvram set def_hwaddr=$new_mac | |
ifdown eth1 | |
wl down | |
# wait 45 seconds and bring wlan back up | |
sleep 45 | |
ifconfig eth1 hw ether $new_mac | |
sleep 2 | |
wl restart | |
ifup eth1 | |
wl up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment