Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- #This script changes the mac address of a specified interface in modern linux OSes using only (mostly) the ifconfig command.
- #It should work out of the box without any third party downloads.
- #Noah B.
- #Last edit 2/2/2016
- #Prompt for root
- [ "$UID" -eq 0 ] || exec sudo bash "$0" "$@"
- int=$1
- #if no int specified, ask for one
- if [ -z "$int" ]
- then
- read -p "Enter interface: " int
- fi
- if [ ! -z "$int" ]
- if ! [ -z $2 ]
- then
- newmac="$2"
- else
- newmac="02:"`cat /dev/urandom | tr -dc 'A-F0-9' | fold -w 10 | head -n 1 | sed 's/\(..\)/\1:/g;s/:$//'`
- fi
- curmac=`ifconfig $int | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'`
- #take down int
- then
- printf "\nTaking down interface...\n\n"
- sleep 1
- ifconfig $int down
- echo "Current (old) MAC for $int: $curmac"
- sleep 1
- #change mac address
- ifconfig $int hw ether $newmac
- #bring up int & restart netmanager
- printf "\nMAC changed, bringing interface up and restarting netman...\n\n"
- sleep 1
- ifconfig $int up
- service network-manager restart
- #update curmac value
- curmac=`ifconfig $int | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'`
- printf "\nCurrent (new) MAC for $int: $curmac\n"
- #ifconfig $int
- else
- echo "error"
- fi
Advertisement
Add Comment
Please, Sign In to add comment