-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy patharp_unix.go
More file actions
38 lines (30 loc) · 707 Bytes
/
arp_unix.go
File metadata and controls
38 lines (30 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// +build !linux,!windows
// only tested on OSX
// decided to go with exec.Command after I couldn't figure
// out how to extract the arp cache out of the kernel with
// golang's syscall or Sysctl()
//
// ... Help appreciated :)
package arp
import (
"os/exec"
"strings"
)
func Table() ArpTable {
data, err := exec.Command("arp", "-an").Output()
if err != nil {
return nil
}
var table = make(ArpTable)
for _, line := range strings.Split(string(data), "\n") {
fields := strings.Fields(line)
if len(fields) < 3 {
continue
}
// strip brackets around IP
ip := strings.Replace(fields[1], "(", "", -1)
ip = strings.Replace(ip, ")", "", -1)
table[ip] = fields[3]
}
return table
}