package main import ( "fmt" "net" ) func main() { mac := make(net.HardwareAddr, 6) _, err := rand.Read(mac) if err != nil { fmt.Println(err) return } fmt.Println(mac) }
package main import ( "fmt" "net" ) func main() { str := "01:23:45:67:89:ab" mac, err := net.ParseMAC(str) if err != nil { fmt.Println(err) return } fmt.Println(mac) }
package main import ( "fmt" "net" ) func main() { mac1, _ := net.ParseMAC("01:23:45:67:89:ab") mac2, _ := net.ParseMAC("cd:ef:01:23:45:67") if mac1.Equal(mac2) { fmt.Println("The MAC addresses are equal") } else { fmt.Println("The MAC addresses are different") } }This example compares two HardwareAddr values using the Equal() method. If the two MAC addresses are equal, it prints a message saying they are equal. Otherwise, it prints a message saying they are different. The net package is the package library used in these examples.