mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-28 16:36:36 +08:00
更好地支持IPv6/优化IP名单内存用量
This commit is contained in:
@@ -1,30 +1,10 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"github.com/cespare/xxhash"
|
||||
"math"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// IP2LongHash 非标地将IP转换为整型
|
||||
// 注意IPv6没有顺序
|
||||
func IP2LongHash(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()))
|
||||
}
|
||||
|
||||
// IsLocalIP 判断是否为本地IP
|
||||
func IsLocalIP(ipString string) bool {
|
||||
var ip = net.ParseIP(ipString)
|
||||
|
||||
Reference in New Issue
Block a user