-
-
Save DewArmy/16a3ba756b145a7523d2 to your computer and use it in GitHub Desktop.
Simple script for 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 | |
# This is an active experiment; use at your own peril. | |
# 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 | |
# # ) | |
# | |
# 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' | |
networkInterface=$(route get "${routeIP}" | egrep -o '(interface.*en)[0-9]+' | cut -d' ' -f2) | |
[[ -z "${networkInterface}" ]] && exit 69; | |
# | |
function default() { | |
ifconfig "${networkInterface}" | grep ether | cut -d" " -f2 | |
} | |
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 | |
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 | |
sudo ifconfig "${networkInterface}" ether "${devices[$val]}" | |
networksetup -setairportpower "${networkInterface}" off; networksetup -setairportpower "${networkInterface}" on | |
echo "Now spoofing $val. Wait for network interface to powercycle." | |
exit 0 | |
else | |
printf "\e[31mbad choice\e[0m\n" | |
exit 64 | |
fi | |
} | |
macycle && exit 0 | |
## To Do | |
# register? script as job | |
# functional MAC address generator | |
# for improved LINUX support: | |
## http://xmodulo.com/spoof-mac-address-network-interface-linux.html | |
# multi hardware port support (BT, etc) | |
# use ```route get 10.10.10.10``` to get network interface to turn off and on. | |
# ```networksetup -setairportpower airport off; networksetup -setairportpower airport on``` assumes wifi though | |
# there is definite room to simplify things. | |
################################### | |
# 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