Created
February 13, 2020 02:42
-
-
Save ryu1/1b87d02926543679b01047a3e7bbac35 to your computer and use it in GitHub Desktop.
Shell Script Chainging MAC Address.
This file contains hidden or 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
| #!/bin/bash | |
| # ------------------------------------------------------------------ | |
| # Change MAC Adress For MacOS | |
| # ------------------------------------------------------------------ | |
| SUBJECT=macaddrchanger | |
| VERSION=0.1.0 | |
| USAGE="Usage: [random|origin] -hv args" | |
| # --- Option processing -------------------------------------------- | |
| while getopts ":vh" optname | |
| do | |
| case "$optname" in | |
| "v") | |
| echo "Version $VERSION" | |
| exit 0; | |
| ;; | |
| "h") | |
| echo $USAGE | |
| exit 0; | |
| ;; | |
| "?") | |
| echo "Unknown option $OPTARG" | |
| exit 0; | |
| ;; | |
| ":") | |
| echo "No argument value for option $OPTARG" | |
| exit 0; | |
| ;; | |
| *) | |
| echo "Unknown error while processing options" | |
| exit 0; | |
| ;; | |
| esac | |
| done | |
| shift $(($OPTIND - 1)) | |
| cmd=$1 | |
| param=$2 | |
| command="command_$1" | |
| # ----------------------------------------------------------------- | |
| LOCK_FILE=/tmp/${SUBJECT}.lock | |
| if [ -f "$LOCK_FILE" ]; then | |
| echo "Script is already running" | |
| exit | |
| fi | |
| # ----------------------------------------------------------------- | |
| trap "rm -f $LOCK_FILE" EXIT | |
| touch $LOCK_FILE | |
| # ----------------------------------------------------------------- | |
| function command_random { | |
| echo Current: `ifconfig en0 ether | grep ether` | |
| SSID=`networksetup -getairportnetwork en0 | sed -E 's/Current Wi-Fi Network: //'` | |
| /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport --disassociate | |
| openssl rand -hex 6 | sed -E 's/(..)/\1:/g; s/./0/2; s/.$//' | xargs sudo ifconfig en0 ether | |
| networksetup -setairportnetwork en0 $SSID | |
| echo Changed: `ifconfig en0 ether | grep ether` | |
| } | |
| function command_origin { | |
| echo Current: `ifconfig en0 ether | grep ether` | |
| SSID=`networksetup -getairportnetwork en0 | sed -E 's/Current Wi-Fi Network: //'` | |
| /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport --disassociate | |
| networksetup -getmacaddress Wi-Fi | awk '{ print $3 }' | xargs sudo ifconfig en0 ether | |
| networksetup -setairportnetwork en0 $SSID | |
| echo Changed: `ifconfig en0 ether | grep ether` | |
| } | |
| # ----------------------------------------------------------------- | |
| # ----------------------------------------------------------------- | |
| if [ -n "$(type -t ${command})" ] && [ "$(type -t ${command})" = function ]; then | |
| ${command} | |
| else | |
| echo "'${cmd}' is NOT a command"; | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment