| 10 | ) |
| 11 | |
| 12 | func Get() (Table, error) { |
| 13 | data, err := exec.Command("ndp", "-an").Output() |
| 14 | if err != nil { |
| 15 | return nil, err |
| 16 | } |
| 17 | |
| 18 | var t Table |
| 19 | header := true |
| 20 | for line := range strings.SplitSeq(string(data), "\n") { |
| 21 | if header { |
| 22 | header = false |
| 23 | continue |
| 24 | } |
| 25 | fields := strings.Fields(line) |
| 26 | if len(fields) < 2 { |
| 27 | continue |
| 28 | } |
| 29 | |
| 30 | if mac := parseMAC(fields[1]); mac != nil { |
| 31 | ip := fields[0] |
| 32 | if idx := strings.IndexByte(ip, '%'); idx != -1 { |
| 33 | ip = ip[:idx] |
| 34 | } |
| 35 | t = append(t, Entry{ |
| 36 | IP: net.ParseIP(ip), |
| 37 | MAC: mac, |
| 38 | }) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | return t, nil |
| 43 | } |