-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmac-changer.sh
More file actions
executable file
·111 lines (87 loc) · 3.63 KB
/
mac-changer.sh
File metadata and controls
executable file
·111 lines (87 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
# Description: this script will find and save your old mac address before changing it.
#############
# variables #
#############
INTERFACE="";
REVERT_MAC="";
OLD_MAC=$(cat old_mac.txt | head -c 18);
CURRENT_MAC=$(ifconfig |grep ether| head -c 31| cut -c 15-31);
NEW_MAC=$(cat /dev/random | tr -cd [:xdigit:] | head -c 10 | sed -r 's/(..)/\1:/g;s/:$//;s/^/02:/'); # translate random gen text to a MAC address
############
# check for root privileges
if [[ $UID != 0 ]]
then
# display message
echo -e "\nPlease run the script with root (sudo) privileges\n";
# exit script with error status
exit;
fi
# display message
echo -e "\nGrabbing and storing current mac address.\n"
# export current MAC address to a file
echo "$CURRENT_MAC" > old_mac.txt;
# logic to validate input
until [[ $REVERT_MAC = "yes" || $REVERT_MAC = "no" ]]
do
# prompt user for input - answer must be 'yes' or 'no'
read -p "Do you want to restore the old mac address? ('yes' or 'no'): " REVERT_MAC;
done
# if revert_mac variable = 'yes' do this.
if [[ $REVERT_MAC = "yes" ]]
then
# prompt for user input
read -p "What is the name of the interface?: " INTERFACE;
# displya message
echo -e "\nYour current MAC address is $CURRENT_MAC\n";
# disable the interface
ifconfig $INTERFACE down;
# change the MAC address to its original value
ifconfig $INTERFACE hw ether $OLD_MAC;
# enable the interface
ifconfig $INTERFACE up;
# display message
echo -e "\nThe original MAC address of $OLD_MAC has been restored.\n";
# exit script with a status code of 0
exit;
# if revert_mac variable = no then do this.
elif [[ $REVERT_MAC = "no" ]]
then
# request user input
read -p "What is the name of the interface?: " INTERFACE;
# display message
echo -e "\nYour current mac is $CURRENT_MAC\n";
echo -e "\nGetting ready to generate a new mac address.\n";
echo -e "\nYour new MAC address is $NEW_MAC\n";
echo -e "\nChanging the MAC address to the new one.\n";
# disable interface
ifconfig $INTERFACE down;
# change MAC address
ifconfig $INTERFACE hw ether $NEW_MAC;
# enable interface
ifconfig $INTERFACE up;
# display message
echo -e "\nThe MAC address has been changed.\n"
fi
#############
# my banner #
#############
##########################################################
# source: http://patorjk.com/software/taag/ #
##########################################################
echo -e "\nScripted by: ";
echo -e "\n";
echo -e "\033[0;5m";
echo " ██▓ ██████▄▄▄█████▓▄▄▄ ▄████▄ ██ ▄█▒███████▒";
echo "▓██▒██ ▒▓ ██▒ ▓▒████▄ ▒██▀ ▀█ ██▄█▒▒ ▒ ▒ ▄▀░";
echo "▒██░ ▓██▄ ▒ ▓██░ ▒▒██ ▀█▄ ▒▓█ ▄▓███▄░░ ▒ ▄▀▒░ ";
echo "░██░ ▒ ██░ ▓██▓ ░░██▄▄▄▄██▒▓▓▄ ▄██▓██ █▄ ▄▀▒ ░";
echo "░██▒██████▒▒ ▒██▒ ░ ▓█ ▓██▒ ▓███▀ ▒██▒ █▒███████▒";
echo "░▓ ▒ ▒▓▒ ▒ ░ ▒ ░░ ▒▒ ▓▒█░ ░▒ ▒ ▒ ▒▒ ▓░▒▒ ▓░▒░▒";
echo " ▒ ░ ░▒ ░ ░ ░ ▒ ▒▒ ░ ░ ▒ ░ ░▒ ▒░░▒ ▒ ░ ▒";
echo " ▒ ░ ░ ░ ░ ░ ▒ ░ ░ ░░ ░░ ░ ░ ░ ░";
echo " ░ ░ ░ ░ ░ ░ ░ ░ ░ ";
echo " ░ ░ ";
echo -e "\033[25m";
echo -e "\n";
###########################################################