mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-04 01:07:49 +02:00
Improving Mac discovery
This commit is contained in:
committed by
Cuong Manh Le
parent
3007cb86ec
commit
76d2e2c226
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user