Jump to content

#!/bin/bash Setting Variable To Mac Addess


bsh
 Share

Recommended Posts

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 ?

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...