From 49d4ac207acea763cd874bcad9eb713b737a9c04 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Tue, 25 Jul 2023 12:26:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96IP=E5=90=8D=E5=8D=95=E4=BD=BF?= =?UTF-8?q?=E7=94=A8IP=E6=90=9C=E7=B4=A2=E6=9F=A5=E8=AF=A2=E9=80=9F?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/db/models/ip_item_dao.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/db/models/ip_item_dao.go b/internal/db/models/ip_item_dao.go index 4feab3de..94074114 100644 --- a/internal/db/models/ip_item_dao.go +++ b/internal/db/models/ip_item_dao.go @@ -14,6 +14,7 @@ import ( "github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/types" "math" + "net" "time" ) @@ -498,7 +499,11 @@ func (this *IPItemDAO) CountAllEnabledIPItems(tx *dbs.Tx, sourceUserId int64, ke } } if len(keyword) > 0 { - query.Like("ipFrom", dbutils.QuoteLike(keyword)) + if net.ParseIP(keyword) != nil { // 是一个IP地址 + query.Attr("ipFrom", keyword) + } else { + query.Like("ipFrom", dbutils.QuoteLike(keyword)) + } } if len(ip) > 0 { query.Attr("ipFrom", ip) @@ -540,7 +545,11 @@ func (this *IPItemDAO) ListAllEnabledIPItems(tx *dbs.Tx, sourceUserId int64, key } } if len(keyword) > 0 { - query.Like("ipFrom", dbutils.QuoteLike(keyword)) + if net.ParseIP(keyword) != nil { // 是一个IP地址 + query.Attr("ipFrom", keyword) + } else { + query.Like("ipFrom", dbutils.QuoteLike(keyword)) + } } if len(ip) > 0 { query.Attr("ipFrom", ip)