mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2026-04-25 05:05:48 +08:00
IP名单改成同时检查多个IP来源
This commit is contained in:
@@ -11,13 +11,16 @@ import (
|
||||
// 将IP转换为整型
|
||||
// 注意IPv6没有顺序
|
||||
func IP2Long(ip string) uint64 {
|
||||
if len(ip) == 0 {
|
||||
return 0
|
||||
}
|
||||
s := net.ParseIP(ip)
|
||||
if s == nil {
|
||||
if len(s) == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
if strings.Contains(ip, ":") {
|
||||
return math.MaxUint32 + xxhash.Sum64String(ip)
|
||||
return math.MaxUint32 + xxhash.Sum64(s)
|
||||
}
|
||||
return uint64(binary.BigEndian.Uint32(s.To4()))
|
||||
}
|
||||
|
||||
@@ -8,4 +8,5 @@ func TestIP2Long(t *testing.T) {
|
||||
t.Log(IP2Long("0.0.0.0.0"))
|
||||
t.Log(IP2Long("2001:db8:0:1::101"))
|
||||
t.Log(IP2Long("2001:db8:0:1::102"))
|
||||
t.Log(IP2Long("::1"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user