-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy patharp_windows.go
49 lines (41 loc) · 888 Bytes
/
arp_windows.go
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
39
40
41
42
43
44
45
46
47
48
49
// +build windows
package arp
// Windows arp table reader added by Claudio Matsuoka.
// Tested only in Windows 8.1, hopefully the arp command output format
// is the same in other Windows versions.
import (
"os/exec"
"strings"
)
func Table() ArpTable {
data, err := exec.Command("arp", "-a").Output()
if err != nil {
return nil
}
var table = make(ArpTable)
skipNext := false
for _, line := range strings.Split(string(data), "\n") {
// skip empty lines
if len(line) <= 0 {
continue
}
// skip Interface: lines
if line[0] != ' ' {
skipNext = true
continue
}
// skip column headers
if skipNext {
skipNext = false
continue
}
fields := strings.Fields(line)
if len(fields) < 2 {
continue
}
ip := fields[0]
// Normalize MAC address to colon-separated format
table[ip] = strings.Replace(fields[1], "-", ":", -1)
}
return table
}