Skip to main content

Randomize and Spoof MAC Address on OS X and Linux

Allure Web Solutions Code Snippet

This little script allows you to randomize and spoof your MAC address on OS X and Linux. Simply run the script in the terminal ./spoof-mac-address and it will ask you which operating system you are on as well as show you what you random MAC address is.

DOWNLOAD THE SCRIPT
#!/usr/bin/env bash
echo "Are you on Mac? [y,n]"
read input
if [[ $input == "Y" || $input == "y" ]]; then
        ## Show active interfaces
        ifconfig | pcregrep -M -o '^[^\t:]+:([^\n]|\n\t)*status: active'

        ## Ask which interface to spoof
        echo "Which interface are you spoofing?"
        read interface

        #################################
        ## Generate random MAC Address ##
        #################################
        MAC=$( openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//' )

        ###################################
        ## Randomize MAC address on OS X ##
        ###################################

        ## Set random address
        sudo ifconfig $interface ether $MAC

        ## Display new address
        ifconfig $interface | grep ether
else
        echo "Are you on Linux? [y,n]"
        read input

        if [[ $input == "Y" || $input == "y" ]]; then

        ## Show active interfaces
        ifconfig | pcregrep -M -o '^[^\t:]+:([^\n]|\n\t)*status: active'

        ## Ask which interface to spoof
        echo "Which interface are you spoofing?"
        read interface

        #################################
        ## Generate random MAC Address ##
        #################################
        MAC=$( openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//' )

        ####################################
        ## Randomize MAC address on Linux ##
        ####################################
        service network-manager stop
        sudo ifconfig $interface down
        sudo ifconfig $interface hw ether $MAC
        sudo ifconfig $interface up
        service network-manager start

        ## Display new address
        echo $MAC

        else
            echo "Use another script foo"
        fi
fi
allure

Author allure

More posts by allure

Leave a Reply

Designed by

best down free | web phu nu so | toc dep 2017