Created
March 25, 2017 16:45
-
-
Save ryanmaynard/60d404f61398a698b49b79106be8c54f to your computer and use it in GitHub Desktop.
Simple MAC address spoofing for Bash on OSX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/local/bin/bash | |
# Macycle expects a declared associateive array in RC file. | |
# # declare -A devices=( | |
# # ['dev1']='aa:aa:aa:aa:aa:aa' | |
# # ['dev2']='bb:bb:bb:bb:bb:bb' #etc | |
# # ) | |
# # | |
# environment stuff | |
unset CDPATH | |
# load config file | |
if [ -f "${HOME}"/.macyclerc ]; then | |
. "${HOME}"/.macyclerc | |
else | |
echo "Configuration file is missing! Checking 'devices[]' array..." | |
if [ "${#devices[@]}" -eq 0 ]; then | |
echo "Device list is empty. Please try adding key-value pairs to 'devices[]' array." | |
exit 65 | |
fi | |
exit 0 | |
fi | |
## test | |
key="${1}" | |
routeIP='8.8.8.8' # Google DNS. | |
networkInterface=$(route get "${routeIP}" | egrep -o '(interface.*en)[0-9]+' | cut -d' ' -f2) | |
[[ -z "${networkInterface}" ]] && exit 69; | |
# | |
function macycle(){ | |
if [ -z "${key}" ] | |
then | |
promptValue | |
else | |
if (("${#devices[$key]}" > 0)) | |
then | |
sudo ifconfig "${networkInterface}" ether "${devices[$key]}" | |
networksetup -setairportpower "${networkInterface}" off; networksetup -setairportpower "${networkInterface}" on | |
echo "Now spoofing $key. Wait for network interface to powercycle." | |
else | |
printf "\e[31mbad choice\e[0m\n" | |
promptValue | |
exit 64 | |
fi | |
fi | |
} | |
function promptValue() { | |
printf "%b" "(\e[38;5;82mactive\e[0m) $(default)\n" | column -t | |
for i in "${!devices[@]}" | |
do | |
printf '%7s\n' "${i} : ${devices[$i]}" | |
done | column -t | |
while read -rp "Choose new MAC address: " val && [ -z "${val}" ]; do :; done | |
if (("${#devices[$val]}" > 0)) | |
then | |
key="${val}" | |
macycle | |
else | |
printf "\e[31mbad choice\e[0m\n" | |
exit 64 | |
fi | |
} | |
function default() { | |
ifconfig "${networkInterface}" | grep ether | cut -d" " -f2 | |
} | |
macycle && exit 0 | |
## To Do | |
# for improved LINUX support: | |
## http://xmodulo.com/spoof-mac-address-network-interface-linux.html | |
################################### | |
# Local Variables: | |
# firestarter: "gist -u edb5e9db9248cc5d7131 %p" | |
# End: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment