yabasoya Posted February 1, 2014 Share Posted February 1, 2014 I have a list of 20 'authorized' macs (will add more as I come across them). I was looking to write a script that runs on startup to query the file of macs and randomly pick one to clone it to wlan1. Can someone help me write a script to do this or at least point me in the right direction? Thanks. Quote Link to comment Share on other sites More sharing options...
markcoker Posted February 1, 2014 Share Posted February 1, 2014 (edited) A bash script like this will should use a random mac (please test as i have not) #!/bin/bash sleep 20 #Wait 20 seconds - Use if you need to wait for other things to load first max=$(wc -l /sd/mac.list) #Count the macs in list (i assume each mac is on a seperate line and only contains MAC?) num=$(( ( RANDOM % $max ) + 1 )) #Get number between 1 - number of macs in file. mac=$(tail -n $num /sd/mac.list| head -n 1) # get random mac macchanger -m $mac #Change to random mac address :) Good Luck, let us know how you go! Edited February 1, 2014 by markcoker Quote Link to comment Share on other sites More sharing options...
yabasoya Posted February 1, 2014 Author Share Posted February 1, 2014 That's beautiful.. Thanks I will try it! Quote Link to comment Share on other sites More sharing options...
yabasoya Posted February 1, 2014 Author Share Posted February 1, 2014 (edited) It just needed a wlan1 on the last line and an extra set of parenthesis on line 4. Without them it was assigning '20 /sd/mac.list' to max, not just '20' #!/bin/bash sleep 20 #Wait 20 seconds - Use if you need to wait for other things to load first max=($(wc -l /sd/mac.list)) #Count the macs in list (i assume each mac is on a seperate line and only contains MAC?) num=$(( ( RANDOM % $max ) + 1 )) #Get number between 1 - number of macs in file. mac=$(tail -n $num /sd/mac.list| head -n 1) # get random mac macchanger -m $mac wlan1 #Change to random mac address :) Thanks for the help! It works in a shh terminal on the pineapple. I just need to test it on a dip switch next. Edited February 1, 2014 by yabasoya Quote Link to comment Share on other sites More sharing options...
markcoker Posted February 4, 2014 Share Posted February 4, 2014 goodstuff,totally missed the mistake on line 4 :) TIP: if your wanting to test your dip setup you could run /usr/bin/dip-handler which ive found handy to test correct dipsetup. 1. So you first just use web interface Configuration > Boot Modes (or edit mk5.db with a db editor of your choice) to edit dip settings & save. 2. Change your dips correct to the settings you want to test. 3. Finally run /usr/bin/dip-handler and those settings will run. Hope it helps. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.