Replace arp from net-tools by ip from iproute2 (linux)

This commit is contained in:
Daniel Rodriguez 2018-01-20 17:04:21 +01:00
parent 3cc5faa297
commit c55284429e
3 changed files with 12 additions and 6 deletions

View file

@ -12,8 +12,8 @@ func ArpUpdate(iface string) (ArpTable, error) {
// Signal we parsed the ARP table at least once.
arp_parsed = true
// Run "arp -an" and parse the output.
output, err := core.Exec("arp", []string{"-a", "-n"})
// Run "arp -an" (darwin) or "ip neigh" (linux) and parse the output
output, err := core.Exec(ArpCmd, ArpCmdOpts)
if err != nil {
return arp_table, err
}
@ -22,9 +22,9 @@ func ArpUpdate(iface string) (ArpTable, error) {
for _, line := range strings.Split(output, "\n") {
m := ArpTableParser.FindStringSubmatch(line)
if len(m) == ArpTableTokens {
address := m[1]
mac := m[2]
ifname := m[3]
address := m[ArpTableTokenIndex[0]]
mac := m[ArpTableTokenIndex[1]]
ifname := m[ArpTableTokenIndex[2]]
if ifname == iface {
new_table[address] = mac