Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- set -e
- get_mac_address() {
- echo $(ifconfig en0 ether | grep ether | rev | cut -d' ' -f2 | rev)
- }
- get_ip_address() {
- echo $(ifconfig en0 inet | grep inet | cut -d' ' -f2)
- }
- set_mac_address() {
- sudo ifconfig en0 ether $1
- }
- set_branch() {
- echo "Updating mac address: $(get_mac_address) -> $1"
- set_mac_address $1
- echo "Done. New MAC: $(get_mac_address)"
- }
- randomise_branch() {
- echo "Current MAC: $(get_mac_address)"
- NEW_MAC=$(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//')
- set_mac_address ${NEW_MAC}
- echo "Done. New MAC: $(get_mac_address)"
- }
- select_branch() {
- IP_ADDRESS=$(get_ip_address)
- DEVICES=$(sudo nmap -sn ${IP_ADDRESS}/24 | awk '/Nmap/{ip=$NF;next} /MAC/{printf "%s|%s|", ip,$3} /MAC/{for(i=4;i<=NF;i++) printf "%s_", $i; printf ";"} ')
- # This part is needlessly clunky as, for whatever reason, the version of bash/sh on MAC misbehaves with arrays -- counts and index iteration didn't work properly
- i=0
- IFS=";" read -ra DEVICE_ARRAY <<< ${DEVICES}
- for DEV in ${DEVICE_ARRAY[@]}; do
- i=$((i+1)) && printf "\t%s) %s\n" "${i}" "${DEV}"
- done
- read -p "Select a device to spoof: " selected
- NEW_MAC=$(echo ${DEVICE_ARRAY} | cut -d' ' -f${selected} | cut -d \| -f2)
- echo "Spoofing MAC address: $(get_mac_address) -> ${NEW_MAC}"
- set_mac_address $NEW_MAC
- echo "Done. New MAC: $(get_mac_address)"
- }
- case $1 in
- --set)
- set_branch $2
- ;;
- --randomise)
- randomise_branch
- ;;
- --select)
- select_branch
- ;;
- *)
- echo "Unknown or no option given"
- exit 64 # User error code
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement