ing
This commit is contained in:
parent
ad40f1baa5
commit
ad1838bb69
|
@ -4,40 +4,15 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
macStripRegexp = regexp.MustCompile(`[^a-fA-F0-9]`)
|
macStripRegexp = regexp.MustCompile(`[^a-fA-F0-9]`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func MacToUint(hwAddr net.HardwareAddr) (uint64, error) {
|
func MacToUint64(hwAddr net.HardwareAddr) (uint64, error) {
|
||||||
mac := hwAddr.String()
|
mac := hwAddr.String()
|
||||||
hex := macStripRegexp.ReplaceAllLiteralString(mac, "")
|
hex := macStripRegexp.ReplaceAllLiteralString(mac, "")
|
||||||
|
|
||||||
return strconv.ParseUint(hex, 16, 64)
|
return strconv.ParseUint(hex, 16, 64)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MacToInt(IPv4Addr net.HardwareAddr) int64 {
|
|
||||||
bits := strings.Split(IPv4Addr.String(), ":")
|
|
||||||
|
|
||||||
b0, _ := strconv.ParseInt(bits[0], 16, 64)
|
|
||||||
b1, _ := strconv.ParseInt(bits[1], 16, 64)
|
|
||||||
b2, _ := strconv.ParseInt(bits[2], 16, 64)
|
|
||||||
b3, _ := strconv.ParseInt(bits[3], 16, 64)
|
|
||||||
b4, _ := strconv.ParseInt(bits[4], 16, 64)
|
|
||||||
b5, _ := strconv.ParseInt(bits[5], 16, 64)
|
|
||||||
|
|
||||||
var sum int64
|
|
||||||
|
|
||||||
//52242420297
|
|
||||||
//52242420297
|
|
||||||
sum += int64(b0) << 40
|
|
||||||
sum += int64(b1) << 32
|
|
||||||
sum += int64(b2) << 24
|
|
||||||
sum += int64(b3) << 16
|
|
||||||
sum += int64(b4) << 8
|
|
||||||
sum += int64(b5)
|
|
||||||
|
|
||||||
return sum
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user