util-go/net/converter/mac.go

19 lines
303 B
Go
Raw Normal View History

2018-08-23 09:01:15 +00:00
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)
}