mirror of
https://github.com/sairson/Yasso.git
synced 2026-06-18 09:47:35 +08:00
Yasso更新大改动,更新扫描方式,去除不常用功能,增加指纹和协议识别,修补bug等
This commit is contained in:
48
pkg/netspy/spy/spy.go
Normal file
48
pkg/netspy/spy/spy.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package spy
|
||||
|
||||
import (
|
||||
"Yasso/core/logger"
|
||||
"Yasso/pkg/netspy/icmp"
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
func GoSpy(ips [][]string, check func(ip string) bool, thread int) []string { // 共有
|
||||
var online []string
|
||||
var wg sync.WaitGroup
|
||||
var ipc = make(chan []string, 10000)
|
||||
var onc = make(chan string, 1000)
|
||||
var count int32
|
||||
if ips == nil {
|
||||
return online
|
||||
}
|
||||
go func() {
|
||||
for _, ipg := range ips {
|
||||
ipc <- ipg
|
||||
}
|
||||
defer close(ipc)
|
||||
}()
|
||||
for i := 0; i < thread; i++ {
|
||||
wg.Add(1)
|
||||
go func(ipc chan []string) {
|
||||
for ipg := range ipc {
|
||||
for _, ip := range ipg {
|
||||
if icmp.Check(ip) {
|
||||
online = append(online, ip) // 此时已经可以证明有一个网段存活了
|
||||
logger.Info(fmt.Sprintf("%s/24 network segment to survive", ip))
|
||||
onc <- fmt.Sprintf("%s/24\n", ip)
|
||||
break // 存在一个主机则证明存活
|
||||
} else {
|
||||
// 不存活
|
||||
continue
|
||||
}
|
||||
}
|
||||
atomic.AddInt32(&count, int32(len(ipg)))
|
||||
}
|
||||
defer wg.Done()
|
||||
}(ipc)
|
||||
}
|
||||
wg.Wait()
|
||||
return online
|
||||
}
|
||||
Reference in New Issue
Block a user