Created
September 21, 2022 05:03
-
-
Save yujqiao/e5861030352611a922ba9a4d70ff32f8 to your computer and use it in GitHub Desktop.
Revisions
-
yujqiao renamed this gist
Sep 21, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
yujqiao created this gist
Sep 21, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ #!/bin/sh mac_blacklist="01:00:8c:fa:1a:ae:d1" leases=$(cat /tmp/dhcp.leases | sed 's/*/unknown/') IFS=' ' online_cnt=0 # grep NUD status, see also https://www.ccexpert.us/routing-tcp-ip-2/neighbor-unreachability-detection.html ip nei | grep -E "(REACHABLE)|(DELAY)" > /tmp/arp_table for line in $leases do ip=$(echo $line | awk '{print $3}') name=$(echo $line | awk '{print $4}') mac=$(echo $line | awk '{print $5}') if ( grep "$ip" /tmp/arp_table > /dev/null) then valid=1 for black in $mac_blacklist do if [[ $black = $mac ]] then valid=0 fi done if [[ $valid -eq 1 ]] then echo $ip "$name" "$mac" online_cnt=$((online_cnt + 1)) fi fi done return $online_cnt