Revise terminology and calc avg staleness
authorSiraaj Khandkar <siraaj@khandkar.net>
Thu, 7 Oct 2021 15:33:05 +0000 (11:33 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Thu, 7 Oct 2021 15:33:05 +0000 (11:33 -0400)
home/bin/arp-recon

index bee996d..e53d2ea 100755 (executable)
@@ -67,8 +67,8 @@ status() {
     local -r log_file="$1"
 
     (
-        echo 'mac ip last first freq dist'
-        echo '--- -- ---- ----- ---- ----'
+        echo 'mac ip staleness_cur staleness_avg age freq dist'
+        echo '--- -- ------------- ------------- --- ---- ----'
         sort -n -k 1 "$log_file" \
         | awk -v now="$(date '+%s')" \
             '
@@ -77,6 +77,7 @@ status() {
                     mac = $2
                     ip = $3
 
+                    interval[mac, ip, intervals[mac, ip]++] = ts - seen_last[mac, ip]
                     freq[mac, ip]++
                     if (!seen_last[mac, ip]  || ts > seen_last[mac, ip] ) seen_last[mac, ip]  = ts
                     if (!seen_first[mac, ip] || ts < seen_first[mac, ip]) seen_first[mac, ip] = ts
@@ -87,14 +88,19 @@ status() {
                         split(key, macip, SUBSEP)
                         mac = macip[1]
                         ip  = macip[2]
-                        last = now - seen_last[mac, ip]
-                        first = now - seen_first[mac, ip]
+                        staleness_cur = now - seen_last[mac, ip]
+                        age = now - seen_first[mac, ip]
                         dist = 100 * (freq[mac, ip] / NR)
+                        intervals_sum = 0
+                        for (i=1; i<=intervals[mac, ip]; i++)
+                            intervals_sum += interval[mac, ip, i]
+                        staleness_avg = intervals_sum / intervals[mac, ip]
                         print \
                             mac, \
                             ip, \
-                            sprintf("%d", last), \
-                            sprintf("%d", first), \
+                            sprintf("%d", staleness_cur), \
+                            sprintf("%d", staleness_avg), \
+                            sprintf("%d", age), \
                             freq[mac, ip], \
                             sprintf("%d", dist)
                     }
This page took 0.040336 seconds and 4 git commands to generate.