Skip to content

Commit 8a96ef5

Browse files
committed
add GetLinuxIPv6Neighbor
1 parent 0eabf48 commit 8a96ef5

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

disc/disc.go

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,44 @@ func StrTobyte16(s string) [16]byte {
179179

180180
// GetARPTable gets ARP table
181181
func (a *disc) GetARPTable() error {
182+
var err1, err2 error
183+
182184
if a.IsBSD {
183-
err1 := a.GetMACOSIPv6Neighbor()
184-
err2 := a.GetMACOSARPTable()
185-
if err1 != nil {
186-
return err1
187-
}
188-
if err2 != nil {
189-
return err2
190-
}
185+
err1 = a.GetMACOSIPv6Neighbor()
186+
err2 = a.GetMACOSARPTable()
191187
} else {
192-
return a.GetLinuxARPTable()
188+
err1 = a.GetLinuxIPv6Neighbor()
189+
err2 = a.GetLinuxARPTable()
190+
}
191+
192+
if err1 != nil {
193+
return err1
194+
}
195+
if err2 != nil {
196+
return err2
197+
}
198+
199+
return nil
200+
}
201+
202+
// GetLinuxIPv6Neighbor gets Linux IPv6 neighbors
203+
func (a *disc) GetLinuxIPv6Neighbor() error {
204+
cmd := exec.Command("ip", "-6", "neighbor", "show")
205+
outBytes, err := cmd.Output()
206+
if err != nil {
207+
return err
193208
}
209+
out := strings.TrimSpace(string(outBytes))
210+
for _, l := range strings.Split(out, "\n") {
211+
fields := strings.Fields(l)
194212

213+
if len(fields) < 6 {
214+
continue
215+
}
216+
217+
//TODO: waiting for Go resolver to lookup ipv6 address to name, the current milestone is Go1.8
218+
a.Table = append(a.Table, ARP{IP: fields[0], Host: "NA", MAC: fields[4], Interface: fields[2]})
219+
}
195220
return nil
196221
}
197222

0 commit comments

Comments
 (0)