Update PortScan.go

This commit is contained in:
I0veD 2025-04-20 17:55:54 +08:00 committed by GitHub
parent fc1962055d
commit 51e54698a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,7 +19,7 @@ type Addr struct {
// ScanResult 扫描结果 // ScanResult 扫描结果
type ScanResult struct { type ScanResult struct {
Address string // IP地址 Address string // IP地址
Port int // 端口号 Port int // 端口号
Service *ServiceInfo // 服务信息 Service *ServiceInfo // 服务信息
} }
@ -45,7 +45,7 @@ func PortScan(hostslist []string, ports string, timeout int64) []string {
// 初始化并发控制 // 初始化并发控制
workers := Common.ThreadNum workers := Common.ThreadNum
addrs := make(chan Addr, 100) // 待扫描地址通道 addrs := make(chan Addr, 100) // 待扫描地址通道
scanResults := make(chan ScanResult, 100) // 扫描结果通道 scanResults := make(chan ScanResult, 100) // 扫描结果通道
var wg sync.WaitGroup var wg sync.WaitGroup
var workerWg sync.WaitGroup var workerWg sync.WaitGroup
@ -120,7 +120,7 @@ func PortConnect(addr Addr, results chan<- ScanResult, timeout int64, wg *sync.W
// 记录开放端口 // 记录开放端口
address := fmt.Sprintf("%s:%d", addr.ip, addr.port) address := fmt.Sprintf("%s:%d", addr.ip, addr.port)
Common.LogInfo(fmt.Sprintf("端口开放 %s", address)) Common.LogSuccess(fmt.Sprintf("端口开放 %s", address))
// 保存端口扫描结果 // 保存端口扫描结果
portResult := &Common.ScanResult{ portResult := &Common.ScanResult{
@ -145,6 +145,7 @@ func PortConnect(addr Addr, results chan<- ScanResult, timeout int64, wg *sync.W
scanner := NewPortInfoScanner(addr.ip, addr.port, conn, time.Duration(timeout)*time.Second) scanner := NewPortInfoScanner(addr.ip, addr.port, conn, time.Duration(timeout)*time.Second)
if serviceInfo, err := scanner.Identify(); err == nil { if serviceInfo, err := scanner.Identify(); err == nil {
result.Service = serviceInfo result.Service = serviceInfo
// 构造服务识别日志 // 构造服务识别日志
var logMsg strings.Builder var logMsg strings.Builder
logMsg.WriteString(fmt.Sprintf("服务识别 %s => ", address)) logMsg.WriteString(fmt.Sprintf("服务识别 %s => ", address))
@ -201,11 +202,8 @@ func PortConnect(addr Addr, results chan<- ScanResult, timeout int64, wg *sync.W
Details: details, Details: details,
} }
Common.SaveResult(serviceResult) Common.SaveResult(serviceResult)
if serviceInfo.Name != "unknown" {
Common.LogSuccess(logMsg.String()) Common.LogSuccess(logMsg.String())
} else {
Common.LogDebug(logMsg.String())
}
} }
} }