mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-26 06:56:36 +08:00
ip2region增加IP格式检查
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
"github.com/lionsoul2014/ip2region/binding/golang/ip2region"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -27,10 +28,13 @@ func (this *IP2RegionLibrary) Lookup(ip string) (*Result, error) {
|
||||
return nil, errors.New("library has not been loaded")
|
||||
}
|
||||
|
||||
// 暂不支持IPv6
|
||||
// 只支持IPv4
|
||||
if strings.Contains(ip, ":") {
|
||||
return nil, nil
|
||||
}
|
||||
if net.ParseIP(ip) == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
// 防止panic发生
|
||||
|
||||
Reference in New Issue
Block a user