IP名单支持IPv6范围

This commit is contained in:
GoEdgeLab
2024-04-06 14:55:29 +08:00
parent 8ea518d7e6
commit 9c6d6e7b8d
13 changed files with 137 additions and 104 deletions

View File

@@ -2,28 +2,12 @@ package utils
import (
"bytes"
"encoding/binary"
"errors"
"github.com/iwind/TeaGo/types"
"net"
"strings"
)
// IP2Long 将IP转换为整型
// 为临时过渡的函数
func IP2Long(ip string) uint64 {
var i = net.ParseIP(ip)
if len(i) == 0 {
return 0
}
if i.To4() != nil {
return uint64(binary.BigEndian.Uint32(i.To4()))
}
// TODO 支持IPv6
return 0
}
// ExtractIP 分解IP
// 只支持D段掩码的CIDR
// 最多只记录255个值