From: Siraaj Khandkar Date: Thu, 7 Oct 2021 15:33:05 +0000 (-0400) Subject: Revise terminology and calc avg staleness X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=83b73f79e224acea204636f6d51c6324e50ac868;p=khome.git Revise terminology and calc avg staleness --- diff --git a/home/bin/arp-recon b/home/bin/arp-recon index bee996d..e53d2ea 100755 --- a/home/bin/arp-recon +++ b/home/bin/arp-recon @@ -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) }