mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-11 18:30:24 +08:00
实现域名、记录同步等API
This commit is contained in:
26
pkg/configutils/ip.go
Normal file
26
pkg/configutils/ip.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package configutils
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"github.com/cespare/xxhash/v2"
|
||||
"math"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// IP2Long 将IP转换为整型
|
||||
// 注意IPv6没有顺序
|
||||
func IP2Long(ip string) uint64 {
|
||||
if len(ip) == 0 {
|
||||
return 0
|
||||
}
|
||||
s := net.ParseIP(ip)
|
||||
if len(s) == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
if strings.Contains(ip, ":") {
|
||||
return math.MaxUint32 + xxhash.Sum64(s)
|
||||
}
|
||||
return uint64(binary.BigEndian.Uint32(s.To4()))
|
||||
}
|
||||
Reference in New Issue
Block a user