Golang 查询 MAC 地址对应的 IP 地址
在 Golang 中,可以使用 net 包中的 LookupAddr 和 LookupMAC 函数来查询 MAC 地址对应的 IP 地址。
示例代码如下:
package main
import (
"fmt"
"net"
)
func main() {
// 定义 MAC 地址
macAddr, err := net.ParseMAC('00:11:22:33:44:55')
if err != nil {
fmt.Println("ParseMAC error:", err)
return
}
// 查询 IP 地址
addrs, err := net.LookupAddr(macAddr.String())
if err != nil {
fmt.Println("LookupAddr error:", err)
return
}
// 输出 IP 地址
for _, addr := range addrs {
fmt.Println(addr)
}
}
运行上述代码,即可查询到 MAC 地址对应的 IP 地址。
原文地址: https://www.cveoy.top/t/topic/fXD4 著作权归作者所有。请勿转载和采集!