bsh Posted January 8, 2012 Posted January 8, 2012 I'm writing a shell script to automate changing my mac addresses. How can I set a variable to equal a mac? for example #!/bin/bash #chg mac and bring up interfaces ifconfig wlan0 down ifconfig wlan1 down macchanger -r wlan0 macchanger -r wlan1 ifconfig wlan0 up ifconfig wlan1 up #GW is new mac address for wlan0 GW=xx:xx:xx:xx:xx:xx #SNIFF is new mac address for wlan1 SNIFF=yy:yy:yy:yy:yy:yy Is there a command that will only return the mac or how do I parse the output of macchanger -s ? Quote
Infiltrator Posted January 8, 2012 Posted January 8, 2012 This example might give you some ideas, of how to set up variables in bash https://community.elearnsecurity.com/index.php?/topic/563-bash-script-to-set-random-mac-and-hostname/ Quote
bsh Posted January 8, 2012 Author Posted January 8, 2012 This example might give you some ideas, of how to set up variables in bash https://community.elearnsecurity.com/index.php?/topic/563-bash-script-to-set-random-mac-and-hostname/ Thanks. That is interesting. He's using md5sum to generate random values; setting them to variables and stringing them together to make a random mac. What could be more interesting, would be to use macchanger to make a valid random mac: GW=`macchanger -A wlan0`; echo $GW Current MAC: 00:60:bb:b6:40:11 (Cabletron - Netlink, Inc.) Faked MAC: 00:dd:00:c7:00:ba (Ungermann-bass Inc.) My problem is $GW has all that crap in it. I just need GW=00:dd:00:c7:00:ba Quote
bsh Posted January 8, 2012 Author Posted January 8, 2012 Solved. GW=`macchanger -s wlan0 | cut -d' ' -f3` export GW In a nutshell, macchanger -s wlan0 will output the string: Current MAC: 00:d0:d2:e7:9c:d1 (Epilog Corporation) The cut command says using space as a delimiter: -d' ' cut out the 3rd field position for me -f3 00:d0:d2:e7:9c:d1 Quote
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.