Last active
July 5, 2016 02:21
-
-
Save paxperscientiam/edb5e9db9248cc5d7131 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 | |
# NEWS (4/7/16) Working. | |
# This is an active experiment; use at your own peril! | |
# Comments and criticism are most welcome! | |
# Motivation, to get devices without captive portal support online. | |
# | |
# | |
# environment stuff | |
unset CDPATH | |
declare -A devices | |
function macycle () { | |
# load config file! | |
if [ -f "${HOME}"/.macyclerc ]; then | |
. "${HOME}"/.macyclerc | |
if [ "${#devices[@]}" -eq 0 ]; then | |
echo "Device list is empty. Please try adding key-value pairs to 'devices[]' array." | |
exit 65 | |
fi | |
else | |
#echo "derp" | |
# while read -rp "RC file '.macyclerc' does not exist. Create one? (y/n): " val && if [[ $val == 'yes' ]]; do ; done | |
# func_configurate || exit 2 | |
echo 'Create ~/.macyclerc' | |
exit 0 | |
fi | |
## test | |
key="${1}" | |
# find networkInterface | |
routeIP='8.8.8.8' # Google DNS. | |
networkInterface=$(route get "${routeIP}" | egrep -o '(interface.*en)[0-9]+' | cut -d' ' -f2) | |
[[ -z "${networkInterface}" ]] && exit 69; | |
# | |
# | |
# | |
if [ -z "${key}" ] | |
then | |
promptValue | |
else | |
if (("${#devices[$key]}" > 0)) | |
then | |
sudo ifconfig "${networkInterface}" ether "${devices[$key]}" || exit 2 | |
printf 'Now spoofing %s. Wait for network interface to powercycle...' "${key}" | |
networksetup -setairportpower "${networkInterface}" off; networksetup -setairportpower "${networkInterface}" on | |
until networksetup -getairportpower en1 | grep -i "on" > /dev/null 2>&1 && route get 8.8.8.8 2>&1 | grep -vi "not in table"; do echo "trying...";sleep 2; done | |
printf 'done.\n' | |
exit 0 | |
else | |
printf "\e[31mbad choice\e[0m\n" | |
promptValue | |
exit 64 | |
fi | |
fi | |
} | |
function promptValue() { | |
printf "%b" "(\e[38;5;82mactive\e[0m) d8:a2:5e:94:49:aa\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 | |
macycle "${val}" | |
else | |
printf "\e[31mbad choice\e[0m\n" | |
exit 64 | |
fi | |
} | |
function default() { | |
ifconfig "${networkInterface}" | grep ether | cut -d" " -f2 | |
} | |
# | |
# | |
function func_menu_help() { | |
e=$(printf "\e") | |
NORMAL="$e[0m" | |
WHITE="$e[1;37m" | |
cat <<EOM | |
${WHITE}macycle -- Transcend the Captive Portal.${NORMAL} | |
A bash program for changing your (WiFi) adapter's | |
Media Access Controller (MAC) address. | |
-c: Create an empty configuration file. | |
EOM | |
} | |
# | |
function func_configurate() { | |
# if no RC, then create "empty" one. | |
# if exists, state as much | |
# allow for adding new content through script | |
tee "${HOME}"/.macyclerc <<EOF | |
declare -A devices=( | |
['dev1']='aa:aa:aa:aa:aa:aa' | |
) | |
EOF | |
} | |
# | |
while getopts "chv" FLAG; do | |
case $FLAG in | |
c) #set c | |
printf 'Create RC file?\n' | |
#func_configurate | |
# touch "${HOME}/.macyclerc" || exit 126 | |
exit 0; | |
;; | |
h|help) #set h | |
func_menu_help | |
exit 0; | |
;; | |
v) # get version | |
printf 'v0.1.1\n' | |
exit 0; | |
;; | |
\?) #unrecognized option - show help | |
echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." | |
exit 2 | |
;; | |
esac | |
done | |
# | |
macycle "${1}" | |
#macycle && exit 0 | |
## To Do | |
# add to bpkg | |
# register? script as job | |
# use networksetup -listallhardwareports for hard-coded MAC addresses | |
# functional MAC address generator | |
# for improved LINUX support: | |
## http://xmodulo.com/spoof-mac-address-network-interface-linux.html | |
# multi hardware port support (BT, etc) | |
# make MAC agnostic | |
# there is definite room to simplify things. | |
################################### | |
# SECTION: Thanks. | |
################################### | |
# eccerr0r and BitJam @ forums.gentoo.org | |
################################### | |
# 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