mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-07-13 12:52:44 +08:00
Update PortScan.go
This commit is contained in:
parent
fc1962055d
commit
51e54698a4
@ -19,7 +19,7 @@ type Addr struct {
|
||||
// ScanResult 扫描结果
|
||||
type ScanResult struct {
|
||||
Address string // IP地址
|
||||
Port int // 端口号
|
||||
Port int // 端口号
|
||||
Service *ServiceInfo // 服务信息
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ func PortScan(hostslist []string, ports string, timeout int64) []string {
|
||||
|
||||
// 初始化并发控制
|
||||
workers := Common.ThreadNum
|
||||
addrs := make(chan Addr, 100) // 待扫描地址通道
|
||||
addrs := make(chan Addr, 100) // 待扫描地址通道
|
||||
scanResults := make(chan ScanResult, 100) // 扫描结果通道
|
||||
var wg 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)
|
||||
Common.LogInfo(fmt.Sprintf("端口开放 %s", address))
|
||||
Common.LogSuccess(fmt.Sprintf("端口开放 %s", address))
|
||||
|
||||
// 保存端口扫描结果
|
||||
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)
|
||||
if serviceInfo, err := scanner.Identify(); err == nil {
|
||||
result.Service = serviceInfo
|
||||
|
||||
// 构造服务识别日志
|
||||
var logMsg strings.Builder
|
||||
logMsg.WriteString(fmt.Sprintf("服务识别 %s => ", address))
|
||||
@ -201,11 +202,8 @@ func PortConnect(addr Addr, results chan<- ScanResult, timeout int64, wg *sync.W
|
||||
Details: details,
|
||||
}
|
||||
Common.SaveResult(serviceResult)
|
||||
if serviceInfo.Name != "unknown" {
|
||||
Common.LogSuccess(logMsg.String())
|
||||
} else {
|
||||
Common.LogDebug(logMsg.String())
|
||||
}
|
||||
|
||||
Common.LogSuccess(logMsg.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user