util/net/converter/mac.go
crusader ad1838bb69 ing
2017-09-11 16:50:25 +09:00

19 lines
303 B
Go

package converter
import (
"net"
"regexp"
"strconv"
)
var (
macStripRegexp = regexp.MustCompile(`[^a-fA-F0-9]`)
)
func MacToUint64(hwAddr net.HardwareAddr) (uint64, error) {
mac := hwAddr.String()
hex := macStripRegexp.ReplaceAllLiteralString(mac, "")
return strconv.ParseUint(hex, 16, 64)
}