feat(arp): 自 go-hua 迁入 ARP 表查询与定时刷新缓存

- IP→MAC 查询(AutoRefresh 后台刷新/Search/Table), 新增依赖 mostlygeek/arp
- 附测试、examples/arp 例程与包 README
This commit is contained in:
2026-09-20 12:29:36 +08:00
parent 8a038d4df3
commit a4920a6a8e
10 changed files with 438 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
//go:build !linux && !windows
// +build !linux,!windows
// only tested on OSX
// decided to go with exec.Command after I couldn't figure
// out how to extract the arp cache out of the kernel with
// golang's syscall or Sysctl()
//
// ... Help appreciated :)
package arp
import (
"os/exec"
"strings"
)
// Table 通过 arp -an 命令读取 ARP 表(类 Unix 平台,仅在 OSX 测试过)
func Table() ArpTable {
data, err := exec.Command("arp", "-an").Output()
if err != nil {
return nil
}
var table = make(ArpTable)
for _, line := range strings.Split(string(data), "\n") {
fields := strings.Fields(line)
if len(fields) < 3 {
continue
}
// strip brackets around IP
ip := strings.Replace(fields[1], "(", "", -1)
ip = strings.Replace(ip, ")", "", -1)
table[ip] = fields[3]
}
return table
}