-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmac_addresschanger.sh
29 lines (24 loc) · 965 Bytes
/
mac_addresschanger.sh
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
#!/usr/bin/env bash
wifi_interface=$(ip link show | grep -o '^[0-9]\+: [a-zA-Z0-9]\+: ' | grep -o '[a-zA-Z0-9]\+' | grep '3' | tail -n 1)
echo "*******************************************"
echo "\........................................./"
echo " YOUR INTERFACE'NAME IS : $wifi_interface"
echo "..........................................."
echo "*******************************************"
if [[ -z "$1" ]]; then
echo "Enter your new MAC address"
elif [[ ! "$1" =~ ^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$ ]]; then
echo "Please provide a valid MAC address"
else
new_mac_address="$1"
echo "Setting new MAC address: $new_mac_address"
sudo ip link set dev "$wifi_interface" down
sudo ip link set dev "$wifi_interface" address "$new_mac_address"
sudo ip link set dev "$wifi_interface" up
if [[ $? -eq 0 ]]; then
echo "MAC address changed successfully"
else
echo "Failed to change MAC address"
fi
fi
echo "bye"