refactor: replace bloom filter with map for deduplication

Bloom filter has false positive risk which can silently drop valid
scan results. Map provides exact deduplication with negligible memory
overhead at the scale of open ports (typically thousands, not millions).
This commit is contained in:
ZacharyZcR
2026-05-13 01:38:48 +08:00
parent af327ee944
commit bc4e657e58
4 changed files with 15 additions and 258 deletions
+4 -5
View File
@@ -328,8 +328,8 @@ func RunIcmp1(hostslist []string, conn *icmp.PacketConn, chanHosts chan string,
var endflag atomic.Bool
var listenerWg sync.WaitGroup
// 创建布隆过滤器用于去重(自动根据主机数量调整大小)
bloomFilter := NewBloomFilter(len(hostslist), 0.01)
// 去重集合:过滤重复的ICMP响应
seen := make(map[string]struct{}, len(hostslist))
// 启动监听协程
listenerWg.Add(1)
@@ -365,11 +365,10 @@ func RunIcmp1(hostslist []string, conn *icmp.PacketConn, chanHosts chan string,
if sourceIP != nil && !endflag.Load() {
ipStr := sourceIP.String()
// 使用布隆过滤器去重,过滤重复的ICMP响应和杂包
if bloomFilter.Contains(ipStr) {
if _, dup := seen[ipStr]; dup {
continue
}
bloomFilter.Add(ipStr)
seen[ipStr] = struct{}{}
livewg.Add(1)
select {