2022-03-15 17:57:46 +00:00
|
|
|
//go:build windows
|
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package aghnet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"net"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newARPDB() *cmdARPDB {
|
|
|
|
return &cmdARPDB{
|
2022-03-30 12:11:57 +00:00
|
|
|
parse: parseArpA,
|
2022-03-15 17:57:46 +00:00
|
|
|
ns: &neighs{
|
|
|
|
mu: &sync.RWMutex{},
|
|
|
|
ns: make([]Neighbor, 0),
|
|
|
|
},
|
2022-03-30 12:11:57 +00:00
|
|
|
cmd: "arp",
|
|
|
|
args: []string{"/a"},
|
2022-03-15 17:57:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// parseArpA parses the output of the "arp /a" command on Windows. The expected
|
|
|
|
// input format (the first line is empty):
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Interface: 192.168.56.16 --- 0x7
|
|
|
|
// Internet Address Physical Address Type
|
|
|
|
// 192.168.56.1 0a-00-27-00-00-00 dynamic
|
|
|
|
// 192.168.56.255 ff-ff-ff-ff-ff-ff static
|
|
|
|
//
|
|
|
|
func parseArpA(sc *bufio.Scanner, lenHint int) (ns []Neighbor) {
|
|
|
|
ns = make([]Neighbor, 0, lenHint)
|
|
|
|
for sc.Scan() {
|
|
|
|
ln := sc.Text()
|
|
|
|
if ln == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
fields := strings.Fields(ln)
|
|
|
|
if len(fields) != 3 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
n := Neighbor{}
|
|
|
|
|
|
|
|
if ip := net.ParseIP(fields[0]); ip == nil {
|
|
|
|
continue
|
|
|
|
} else {
|
|
|
|
n.IP = ip
|
|
|
|
}
|
|
|
|
|
|
|
|
if mac, err := net.ParseMAC(fields[1]); err != nil {
|
|
|
|
continue
|
|
|
|
} else {
|
|
|
|
n.MAC = mac
|
|
|
|
}
|
|
|
|
|
|
|
|
ns = append(ns, n)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ns
|
|
|
|
}
|