feat(netx): 自 go-hua/common 迁入本机网络信息工具并独立成包

- 枚举 IPv4 地址与 MAC 地址(过滤回环与虚拟网卡),附测试、例程与 README
This commit is contained in:
2026-09-20 12:20:50 +08:00
parent f04a14d6bb
commit 792335a3cb
4 changed files with 107 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
package netx
import "testing"
func TestGetLocalIpAndMac(t *testing.T) {
ips, err := GetLocalIp()
if err != nil {
t.Fatalf("GetLocalIp: %v", err)
}
if len(ips) == 0 {
t.Log("本机无 IPv4 地址(CI 环境可能出现)")
}
macs, err := GetLocalMac()
if err != nil {
t.Fatalf("GetLocalMac: %v", err)
}
if len(macs) == 0 {
t.Log("本机未采集到 MAC 地址(CI 环境可能出现)")
}
// 不应包含空串(无硬件地址的虚拟网卡已被过滤)
for _, m := range macs {
if m == "" {
t.Error("MAC 列表不应包含空串")
}
}
}