Skip to content

Instantly share code, notes, and snippets.

View 777okhtar's full-sized avatar
😎
Three sevens are an M

777okhtar 777okhtar

😎
Three sevens are an M
View GitHub Profile
@777okhtar
777okhtar / macaddr.go
Created January 24, 2022 08:03 — forked from liasica/macaddr.go
a simple example of how to grab a mac address in Golang.
// getMacAddr gets the MAC hardware
// address of the host machine
func getMacAddr() (addr string) {
interfaces, err := net.Interfaces()
if err == nil {
for _, i := range interfaces {
if i.Flags&net.FlagUp != 0 && bytes.Compare(i.HardwareAddr, nil) != 0 {
// Don't use random as we have a real address
addr = i.HardwareAddr.String()
break
@777okhtar
777okhtar / macUint64.go
Created January 24, 2022 07:39 — forked from tsilvers/macUint64.go
Golang code to get MAC address for purposes of generating a unique id. Returns a uint64. Skips virtual MAC addresses (Locally Administered Addresses).
package main
import (
"bytes"
"fmt"
"net"
)
func main() {
fmt.Printf("MAC: %16.16X\n", macUint64())