4 #set -u # Error on unset var
8 # - log (to stdout or file):
9 # run arp-scan and convert output to our log format
13 # - status (from stdin or file):
15 # - seen devices, sorted by last-seen
21 # - [ ] Gather more info on each device. How? nmap?
28 local -r level
="$1"; shift
29 local -r fmt="$1\n"; shift
32 printf '%s [%s] ' "$(date '+%Y-%m-%d %H:%M:%S')" "$level" >&2
33 printf "$fmt" $args >&2
41 if [[ -n "$_debug" ]]; then
47 local -r interval
="$1"
48 local -r log_file
="$2"
52 sudo arp-scan
--localnet;
57 /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ {
67 local -r log_file
="$1"
70 echo 'mac ip last first freq dist'
71 echo '--- -- ---- ----- ---- ----'
72 sort -n -k 1 "$log_file" \
73 |
awk -v now
="$(date '+%s')" \
81 if (!seen_last[mac, ip] || ts > seen_last[mac, ip] ) seen_last[mac, ip] = ts
82 if (!seen_first[mac, ip] || ts < seen_first[mac, ip]) seen_first[mac, ip] = ts
87 split(key, macip, SUBSEP)
90 last = now - seen_last[mac, ip]
91 first = now - seen_first[mac, ip]
92 dist = 100 * (freq[mac, ip] / NR)
96 sprintf("%d", last), \
97 sprintf("%d", first), \
123 log_file
='/dev/stdout'
125 if [[ -n "$2" ]]; then
127 if [[ -n "$3" ]]; then
131 debug
'(>) log | interval:"%s" log_file:"%s"' "$interval" "$log_file"
132 log
"$interval" "$log_file"
133 debug
'(.) log | interval:"%s" log_file:"%s"' "$interval" "$log_file"
136 log_file
='/dev/stdin'
137 if [[ -n "$2" ]]; then
140 debug
'(>) status | log_file:"%s"' "$log_file"
142 debug
'(.) status | log_file:"%s"' "$log_file"
145 error
'Unknown command: "%s"' "$cmd"
This page took 0.098157 seconds and 4 git commands to generate.