Created
October 10, 2017 01:25
-
-
Save Ophirr33/edb20f646c0145b9fada9fb33aac5375 to your computer and use it in GitHub Desktop.
New IP
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
#!/usr/bin/env bash | |
# WARNING: sed abuse ahead | |
set -e | |
# First, find out what interface you're using | |
INTERFACE=$(ifconfig | grep -e "RUNNING" | grep -v "LOOPBACK" | sed -e "s/:.*//") | |
# Then, get your current mac address | |
OLDMAC=$(ifconfig | awk "/$INTERFACE/{f=1} f{print; if (/ether/) exit}" | grep -e "ether" | sed -e 's/^.*ether \(.\{17\}\)\(.*\)/\1/') | |
# Get a new mac address | |
END=$(echo $OLDMAC | sed -e "s/.*:\(..$\)/\1/") | |
if [ "$END" == "ff" ] | |
then | |
NEWEND="00" | |
else | |
# Increment by one | |
NEWEND=$(printf "0x%02X" $((0x$END + 0x1)) | sed -e "s/0x\(..\)/\1/") | |
fi | |
NEWMAC="$(echo $OLDMAC | sed -e "s/\(.\{15\}\)\(..\)/\1/")$NEWEND" | |
echo "Change '$OLDMAC' to '$NEWMAC' on interface '$INTERFACE' [y/n]? " | |
read answer | |
# Change MAC address of INTERFACE | |
if [ "$answer" == "y" ] | |
then | |
echo "Resetting..." | |
sudo ifconfig $INTERFACE down && sudo ifconfig $INTERFACE hw ether $NEWMAC && sudo ifconfig $INTERFACE up | |
sudo systemctl restart NetworkManager | |
echo "Done" | |
exit 0 | |
else | |
echo "Quitting" | |
exit 1 | |
fi | |
# Now just reconnect to the wifi! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment