diff options
author | kartofen <mladenovnasko0@gmail.com> | 2023-04-01 19:00:10 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2023-04-01 19:00:10 +0300 |
commit | 45d2b7e9740e98a8168ffb230cbe6821dab47984 (patch) | |
tree | d2724ad6046040a5f40521fba54a870524bfdc6a | |
parent | 0509185cbf885c62c82362a132c71d80c5e82074 (diff) |
-rwxr-xr-x | bigMAC.sh | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -9,13 +9,16 @@ for dep in "${deps[@]}"; do 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" +interface=$(ip route get 8.8.8.8 | awk '{print $5}') # usually wlp2s0 + +timeperiod=$((20)) # timeperiod=$((60 * 60 * 3)) + +function log { + printf "\033[0;33m%s\033[0m $1" "$(date '+%b %d %T')" +} function get_macs { while true; do n=0 @@ -26,7 +29,7 @@ function get_macs { 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 + ((n > 0)) && log "Wrote $n new addresses to $macs_file\n" || true done } @@ -37,14 +40,14 @@ function set_ip_address { sleep 2 } -function taste-macs { +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" + log "Wrote '$addr' to $succ_file" fi fi done < "$macs_file" @@ -54,5 +57,5 @@ function taste-macs { while true; do get_macs & sleep "$timeperiod"; kill $! - taste-macs + taste_macs done |