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
+43
View File
@@ -0,0 +1,43 @@
//go:build linux
// +build linux
package arp
import (
"bufio"
"os"
"strings"
)
const (
f_IPAddr int = iota
f_HWType
f_Flags
f_HWAddr
f_Mask
f_Device
)
// Table 读取 Linux 内核 ARP 表(/proc/net/arp)
func Table() ArpTable {
f, err := os.Open("/proc/net/arp")
if err != nil {
return nil
}
defer f.Close()
s := bufio.NewScanner(f)
s.Scan() // skip the field descriptions
var table = make(ArpTable)
for s.Scan() {
line := s.Text()
fields := strings.Fields(line)
table[fields[f_IPAddr]] = fields[f_HWAddr]
}
return table
}