func nmap(startPort int, EndPort int, url string) {
ports := []int{}
var wait sync.WaitGroup
wait.Add(1)
for i := startPort; i < EndPort; i++ {
go func(p int) {
host := fmt.Sprintf("%s:%d", url, p)
_, re := net.DialTimeout("tcp", host, time.Millisecond*300)
if re == nil {
ports = append(ports, p)
}
if p == EndPort-1 {
wait.Done()
}
}(i)
}
wait.Wait()
for _, item := range ports {
fmt.Println(item)
}
}
golang 实现tcp 扫描器
最新推荐文章于 2023-01-19 23:15:46 发布