diff --git a/core/WebDetection.go b/core/WebDetection.go index 464d6d9..37a099c 100644 --- a/core/WebDetection.go +++ b/core/WebDetection.go @@ -9,6 +9,7 @@ import ( "regexp" "strconv" "strings" + "sync" "time" "github.com/shadow1ng/fscan/common" @@ -24,6 +25,10 @@ type WebPortDetector struct { httpClient *http.Client // HTTPS客户端 httpsClient *http.Client + // 检测结果缓存(避免重复检测) + detectionCache map[string]bool + // 缓存互斥锁 + cacheMutex sync.RWMutex } // NewWebPortDetector 创建Web端口检测器 @@ -119,6 +124,7 @@ func NewWebPortDetector() *WebPortDetector { httpTimeout: timeout, httpClient: httpClient, httpsClient: httpsClient, + detectionCache: make(map[string]bool), } } @@ -130,9 +136,25 @@ func (w *WebPortDetector) IsWebService(host string, port int) bool { return true } - // 2. 智能路径:对非常见端口进行HTTP协议探测 + // 2. 缓存检查:避免重复检测同一端口 + cacheKey := fmt.Sprintf("%s:%d", host, port) + w.cacheMutex.RLock() + if cached, exists := w.detectionCache[cacheKey]; exists { + w.cacheMutex.RUnlock() + common.LogDebug(fmt.Sprintf("端口 %d 使用缓存结果: %v", port, cached)) + return cached + } + w.cacheMutex.RUnlock() + + // 3. 智能路径:对非常见端口进行HTTP协议探测 common.LogDebug(fmt.Sprintf("对端口 %d 进行智能Web检测", port)) result := w.detectHTTPService(host, port) + + // 4. 缓存结果 + w.cacheMutex.Lock() + w.detectionCache[cacheKey] = result + w.cacheMutex.Unlock() + common.LogDebug(fmt.Sprintf("端口 %d 智能检测结果: %v", port, result)) return result }