ip2region增加IP格式检查

This commit is contained in:
刘祥超
2021-06-27 17:29:16 +08:00
parent 4bc6f93902
commit 4869c11d60
2 changed files with 28 additions and 1 deletions

View File

@@ -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发生