# DD-WRT Routers used. WHR-300HP WNDR3700 WRT54GL # Sample DHCP entries host HostName-mgwireless { hardware ethernet 00:22:FA:EE:EF:BC; fixed-address xxx.xxx.xxx.xxx; } host MGGizmo-mgwireless-1 { hardware ethernet B8:FF:61:A4:06:86; } # If you need to look through macfile here is one way. for i in $( cat macfile ); do echo $i; done #!/bin/bash # Get the mac addresses from the /etc/dhcp/dhcpd.conf DHCPCONF='/etc/dhcp/dhcpd.conf' MACFILE='/etc/tools/macfile' REMFILE='macfile' # Echo what we will find out to the console grep mgwireless ${DHCPCONF} # Now do the full extraction MACADDS=$(grep mgwireless ${DHCPCONF} | awk -F{ '{print $2}' | awk '{printf substr(toupper($3),1,length($3)-1)" "}' | awk '{print substr($0,1,length($0)-1)}') echo ${MACADDS} > ${MACFILE} ################################################### # Please only add devices that use wl0_maclist here. # WRT54GL ################################################### echo "Starting push on wl0_maclist" # APLIST - Is the listing of AP in the MG Campus APLIST=( 172.16.100.xxx 172.16.100.xxx 172.16.100.xxx 172.16.100.xxx ) # Set the number of IP Addresses aplistnum=${#APLIST[@]} # For each APLIST entry push out the MACADDS to each via ssh for ((i=0;i<$aplistnum;i++)); do echo Attempting ssh ${APLIST[${i}]} #echo ssh ${APLIST[${i}]} "(nvram set wl0_maclist=\"${MACADDS}\";nvram commit)" #DDWRTCMD="\'nvram set wl0_maclist=\"${MACADDS}\";nvram commit;reboot;\'" scp ${MACFILE} ${APLIST[${i}]}: ssh ${APLIST[${i}]} "(nvram set wl0_maclist=\"\`cat ${REMFILE}\`\";nvram commit;reboot)" #ssh ${APLIST[${i}]} ${DDWRTCMD} done echo "Ending push on wl0_maclist" ################################################### # WNDR3700v2 - supporting ath0_maclist ath1_maclist ################################################### echo "Starting push to WNDR3700v2 on ath0_maclist ath1_maclist" # APLIST - Is the listing of AP in the MG Campus APLIST=( 172.16.100.xxx 172.16.100.xxx 172.16.100.xxx 172.16.100.xxx ) # Set the number of IP Addresses aplistnum=${#APLIST[@]} # For each APLIST entry push out the MACADDS to each via ssh for ((i=0;i<$aplistnum;i++)); do echo Attempting ssh ${APLIST[${i}]} scp ${MACFILE} ${APLIST[${i}]}: ssh ${APLIST[${i}]} "(nvram set ath0_maclist=\"\`cat ${REMFILE}\`\";nvram set ath1_maclist=\"\`cat ${REMFILE}\`\";nvram commit;reboot)" done echo "Ending push to WNDR3700v2 on ath0_maclist ath1_maclist" ################################################### # WHR-300HP - supporting ath0_maclist ################################################### echo "Starting push to WHR-300HP on ath0_maclist" # APLIST - Is the listing of AP in the MG Campus APLIST=( 172.16.100.xxx 172.16.100.xxx 172.16.100.xxx 172.16.100.xxx ) # Set the number of IP Addresses aplistnum=${#APLIST[@]} # For each APLIST entry push out the MACADDS to each via ssh for ((i=0;i<$aplistnum;i++)); do echo Attempting ssh ${APLIST[${i}]} scp ${MACFILE} ${APLIST[${i}]}: ssh ${APLIST[${i}]} "(nvram set ath0_maclist=\"\`cat ${REMFILE}\`\";nvram commit;reboot)" done echo "Ending push to WHR-300HP on ath0_maclist" echo "Goodbye!"