-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacanon
executable file
·132 lines (105 loc) · 2.42 KB
/
macanon
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
declare PGL="${1}";
declare -a ALL_DEVICES=();
declare DEVICE;
declare PERM;
declare CURR;
_main() {
sudo -v;
_setAllDevices;
_chooseDevice;
_findPerm;
_findCurr;
_changeMac;
};
_chooseDevice() {
_c green;
_printAllDevices;
echo;
echo '==> Enter device: ';
echo "$(_line)";
printf '==> ';
_u;
local -i choice;
local -i i;
read -p "" choice; # todo: validate
i=$((${choice}-1));
DEVICE="${ALL_DEVICES[${i}]}";
DEVICE="$(echo "${DEVICE}" | sed 's/^[0-9]\+: \(.*\)/\1/')";
# echo "${DEVICE}";
};
_setAllDevices() {
local device;
while read -r device; do
ALL_DEVICES+=("${device}");
done <<< "$(_listDevices)";
};
_listDevices() {
ip link show |
grep --color='never' "^[0-9]" |
sed -re 's/([0-9].*?):.*/\1/';
};
_printAllDevices() {
local device;
for device in "${ALL_DEVICES[@]}"; do
echo "${device}";
done;
};
_findPerm() {
PERM="$(sudo macchanger -s "${DEVICE}" | tail -n 1)";
PERM="$(echo "${PERM}" | sed 's/^Permanent MAC:\s\+\([0-9A-Za-z:]*\)\s(.*/\1/')";
};
_findCurr() {
CURR="$(sudo macchanger -s "${DEVICE}" | head -n 1)";
CURR="$(echo "${CURR}" | sed 's/^Current MAC:\s\+\([0-9A-Za-z:]*\)\s(.*/\1/')";
};
_changeMac() {
# nmcli d disconnect "${DEVICE}";
# nmcli radio wifi off;
sudo ip link set "${DEVICE}" down;
if [ "${CURR}" = "${PERM}" ]; then
sudo macchanger -a "${DEVICE}";
[ -n "${PGL}" ] && _launchPglgui;
else
sudo macchanger -p "${DEVICE}";
fi;
# nmcli radio wifi on;
# nmcli d connect "${DEVICE}";
sudo ip link set "${DEVICE}" up;
_waitUntilConnected;
};
_launchPglgui() {
pglgui &>/dev/null &disown;
};
_waitUntilConnected() {
ping google.com -c 1 &>/dev/null;
[ $? -eq 0 ] && return; # base case
sleep 0.1s;
_waitUntilConnected; # recursive case
};
_c() {
local -r name="${1}";
local -Ar codes=(
["black"]="0"
["red"]="1"
["green"]="2"
["yellow"]="3"
["blue"]="4"
["magenta"]="5"
["cyan"]="6"
["white"]="7"
);
local -r code="${codes[$name]}"
[ -n "${code}" ] && tput setaf "${code}";
[ -z "${*:2}" ] && return 0;
eval "${@:2}";
_ifErr "Failed to run '${*:2}'";
tput sgr0;
};
_u() {
tput sgr0;
};
_line() {
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =;
};
_main;