Skip to content

Instantly share code, notes, and snippets.

@mikedoubintchik
Created March 3, 2017 23:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikedoubintchik/91ac859e3f588c3714de646503ca7fab to your computer and use it in GitHub Desktop.
Save mikedoubintchik/91ac859e3f588c3714de646503ca7fab to your computer and use it in GitHub Desktop.
Here's a little bash script snippet for randomizing and spoofing your MAC address both on OS X and Linux
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment