33 lines
514 B
Go
33 lines
514 B
Go
package arp
|
|
|
|
import (
|
|
"bufio"
|
|
"net"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func lookup() (map[string]net.HardwareAddr, error) {
|
|
f, err := os.Open("/proc/net/arp")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer func() { _ = f.Close() }()
|
|
|
|
t := make(map[string]net.HardwareAddr)
|
|
s := bufio.NewScanner(f)
|
|
for i := 0; s.Scan(); i++ {
|
|
if i == 0 {
|
|
continue
|
|
}
|
|
line := strings.Fields(s.Text())
|
|
if len(line) < 4 {
|
|
continue
|
|
}
|
|
if mac, err := net.ParseMAC(line[3]); err == nil {
|
|
t[line[0]] = mac
|
|
}
|
|
}
|
|
return t, nil
|
|
}
|