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/gIY6 著作权归作者所有。请勿转载和采集!