Improving Mac discovery

This commit is contained in:
Cuong Manh Le
2023-07-14 16:53:17 +00:00
committed by Cuong Manh Le
parent 3007cb86ec
commit 76d2e2c226
22 changed files with 1229 additions and 291 deletions
+28
View File
@@ -0,0 +1,28 @@
package clientinfo
import (
"bufio"
"os"
"strings"
)
const procNetArpFile = "/proc/net/arp"
func (a *arpDiscover) scan() {
f, err := os.Open(procNetArpFile)
if err != nil {
return
}
defer f.Close()
s := bufio.NewScanner(f)
s.Scan() // skip header
for s.Scan() {
line := s.Text()
fields := strings.Fields(line)
ip := fields[0]
mac := fields[3]
a.mac.Store(ip, mac)
a.ip.Store(mac, ip)
}
}