-
Notifications
You must be signed in to change notification settings - Fork 46
/
worker.go
68 lines (59 loc) · 1.02 KB
/
worker.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"bufio"
"log"
"os"
"sync"
)
var (
ProcChan = make(chan *ProcJob, maxWorkers)
writer, _ = NewCSVWriter(OUTCSV)
)
type ProcJob struct {
Host string
}
func ProcessHosts(args []string) {
if len(inpFile) > 0 {
file, err := os.Open(inpFile)
if err != nil {
log.Println(err)
return
}
defer file.Close()
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
ProcChan <- &ProcJob{
Host: scanner.Text(),
}
}
if err := scanner.Err(); err != nil {
log.Fatalln("Error reading from target file:", err.Error())
}
} else {
for _, target := range args {
ProcChan <- &ProcJob{
Host: target,
}
}
}
close(ProcChan)
}
func execWorker(wg *sync.WaitGroup) {
for job := range ProcChan {
job.RunChecks()
}
wg.Done()
}
func InitDispatcher(workerno int) {
wg := new(sync.WaitGroup)
for i := 0; i < workerno; i++ {
wg.Add(1)
go execWorker(wg)
}
wg.Wait()
}
func (p *ProcJob) RunChecks() {
p.FingerPrint()
p.ExecuteCrawler()
}