util-go/net/converter/mac.go
crusader 7d0f0cdbd5 ing
2018-08-23 18:01:15 +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)
}