mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-09-14 05:56:46 +08:00
refactor: 清理无法访问的死代码函数
移除项目中无法访问的死代码: - 移除 Scanner.go 中的 logScanPlan 函数 - 移除 match_engine.go 中的 containsPort 和 IsPortMatch 函数 - 清理相关的未使用导入:strings、strconv 优化效果: - 减少约60行无用代码 - 消除编译器 unreachable func 警告 - 提升代码可维护性和可读性 - 优化二进制文件大小 这些函数在参数精简过程中失去了调用者,成为死代码。 移除后核心功能保持完整,通过完整测试验证。
This commit is contained in:
parent
f943f04de7
commit
647860f170
@ -6,7 +6,6 @@ import (
|
||||
"github.com/shadow1ng/fscan/common/i18n"
|
||||
"github.com/shadow1ng/fscan/webscan/lib"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
)
|
||||
@ -140,24 +139,6 @@ func prepareScanTasks(targets []common.HostInfo, pluginsToRun []string, isCustom
|
||||
return tasks
|
||||
}
|
||||
|
||||
// logScanPlan 输出扫描计划信息
|
||||
func logScanPlan(tasks []ScanTask) {
|
||||
// 统计每个插件的目标数量
|
||||
pluginCounts := make(map[string]int)
|
||||
for _, task := range tasks {
|
||||
pluginCounts[task.pluginName]++
|
||||
}
|
||||
|
||||
// 构建扫描计划信息
|
||||
var planInfo strings.Builder
|
||||
planInfo.WriteString("扫描计划:\n")
|
||||
|
||||
for plugin, count := range pluginCounts {
|
||||
planInfo.WriteString(fmt.Sprintf(" - %s: %d 个目标\n", plugin, count))
|
||||
}
|
||||
|
||||
common.LogBase(planInfo.String())
|
||||
}
|
||||
|
||||
// 调度单个扫描任务
|
||||
func scheduleScanTask(pluginName string, target common.HostInfo, ch *chan struct{}, wg *sync.WaitGroup) {
|
||||
|
@ -3,7 +3,6 @@ package portfinger
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/shadow1ng/fscan/common"
|
||||
@ -95,49 +94,6 @@ func (p *Probe) getSoftMatch(data string) (softMatch Match, err error) {
|
||||
return softMatch, nil
|
||||
}
|
||||
|
||||
// containsPort 检查指定端口是否在探测器的端口范围内(私有方法)
|
||||
func (p *Probe) containsPort(testPort int) bool {
|
||||
common.LogDebug(fmt.Sprintf("检查端口 %d 是否在探测器端口范围内: %s", testPort, p.Ports))
|
||||
|
||||
// 检查单个端口
|
||||
ports := strings.Split(p.Ports, ",")
|
||||
for _, port := range ports {
|
||||
port = strings.TrimSpace(port)
|
||||
cmpPort, err := strconv.Atoi(port)
|
||||
if err == nil && testPort == cmpPort {
|
||||
common.LogDebug(fmt.Sprintf("端口 %d 匹配单个端口", testPort))
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// 检查端口范围
|
||||
for _, port := range ports {
|
||||
port = strings.TrimSpace(port)
|
||||
if strings.Contains(port, "-") {
|
||||
portRange := strings.Split(port, "-")
|
||||
if len(portRange) != 2 {
|
||||
common.LogDebug("无效的端口范围格式: " + port)
|
||||
continue
|
||||
}
|
||||
|
||||
start, err1 := strconv.Atoi(strings.TrimSpace(portRange[0]))
|
||||
end, err2 := strconv.Atoi(strings.TrimSpace(portRange[1]))
|
||||
|
||||
if err1 != nil || err2 != nil {
|
||||
common.LogDebug(fmt.Sprintf("解析端口范围失败: %s", port))
|
||||
continue
|
||||
}
|
||||
|
||||
if testPort >= start && testPort <= end {
|
||||
common.LogDebug(fmt.Sprintf("端口 %d 在范围 %d-%d 内", testPort, start, end))
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
common.LogDebug(fmt.Sprintf("端口 %d 不在探测器端口范围内", testPort))
|
||||
return false
|
||||
}
|
||||
|
||||
// MatchPattern 检查响应是否与匹配规则匹配
|
||||
func (m *Match) MatchPattern(response []byte) bool {
|
||||
@ -161,13 +117,4 @@ func (m *Match) MatchPattern(response []byte) bool {
|
||||
return matched
|
||||
}
|
||||
|
||||
// IsPortMatch 检查探测器是否适用于指定端口
|
||||
func (p *Probe) IsPortMatch(port int) bool {
|
||||
// 如果没有指定端口范围,认为适用于所有端口
|
||||
if p.Ports == "" {
|
||||
return true
|
||||
}
|
||||
|
||||
return p.containsPort(port)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user