Refer:https://github.com/evilsocket/brutemachine

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"sync"
"fmt"
"strconv"
"time"
//"runtime"
)
var wait sync.WaitGroup
var input = make(chan string)
func inputConsumer() {
for in := range input {
fmt.Println(in)
if in=="2" {
for i:=1; i<10 ;i++{
wait.Add(1)
input <- "hello"
}
}
//println(runtime.NumGoroutine(),"===")
time.Sleep(time.Second)
wait.Done()
}
}
func main() {
//控制goroutine数量为10个
for i := 0; i <10; i++ {
go inputConsumer()
}
for j:=1 ;j<20;j++ {
wait.Add(1)
input <- strconv.Itoa(j)
}
wait.Wait()
}