-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMACchange.sh
More file actions
80 lines (67 loc) · 2.51 KB
/
MACchange.sh
File metadata and controls
80 lines (67 loc) · 2.51 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
#!/bin/bash
#check for root privileges
if [ "$EUID" -ne 0 ]; then
echo "This script must be run by a user with sudo privileges."
exit 1
fi
#check if macchanger is installed (or not)
if ! command -v macchanger &> /dev/null; then
echo "Macchanger binary not found. Installing..."
sudo apt-get update -y && sudo apt-get install macchanger -y
fi
echo "What type of network do you wish to randomize?"
echo " "
echo "#1. eth"
echo "#2. wlan"
echo " "
read input
#list all the available interfaces and get user-input
if [[ $input == 1 ]]; then
interfaces=$(ip link show | grep eth | awk '{print $2}' | tr -d ':')
echo "Available Ethernet interfaces: $interfaces"
read -p "Enter the Ethernet interface you want to randomize: " type_eth
# Validate interface
if ! ifconfig $type_eth &> /dev/null; then
echo "$type_eth not found. Please check the device name."
exit 1
fi
#randomize the MAC address using macchanger
echo "Randomizing MAC for $type_eth..."
sudo macchanger -r $type_eth
echo "Randomized MAC for $type_eth"
else
interfaces=$(ip link show | grep wlan | awk '{print $2}' | tr -d ':')
echo "Available WLAN interfaces: $interfaces"
read -p "Enter the WLAN interface you want to randomize: " type_wlan
#Validate interface
if ! ifconfig $type_wlan &> /dev/null; then
echo "$type_wlan not found. Please check the device name."
exit 1
fi
#randomize MAC address using macchanger
echo "Randomizing MAC for $type_wlan..."
sudo macchanger -r $type_wlan
echo "Randomized MAC for $type_wlan"
fi
#check global network connectivity after MAC change (ping to google dns for verif.)
echo "Checking network connectivity..."
if ! ping -c 3 8.8.8.8 &> /dev/null; then
echo "Network is not reachable after changing MAC address. Check your connection."
else
echo "Network is reachable."
fi
#offer user to revert to original/previous MAC address
read -p "Would you like to revert to the original MAC address? (y/n): " revert
if [ "$revert" == "y" ]; then
if [[ $input == 1 ]]; then
sudo macchanger -p $type_eth
echo "Original MAC restored for $type_eth."
else
sudo macchanger -p $type_wlan
echo "Original MAC restored for $type_wlan."
fi
fi
#log the MAC change event to a log file
log_file="/var/log/mac_randomizer.log"
echo "$(date) - Changed MAC for $type_eth/$type_wlan" >> $log_file
echo "Script finished."