Files
zogo/arp/arp_linux.go
4566704 a4920a6a8e feat(arp): 自 go-hua 迁入 ARP 表查询与定时刷新缓存
- IP→MAC 查询(AutoRefresh 后台刷新/Search/Table), 新增依赖 mostlygeek/arp
- 附测试、examples/arp 例程与包 README
2026-09-20 12:29:36 +08:00

44 lines
563 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//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
}