-
Notifications
You must be signed in to change notification settings - Fork 307
/
scanner.go
48 lines (42 loc) · 1.17 KB
/
scanner.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
package zgrab2
import (
"fmt"
"log"
"time"
)
var scanners map[string]*Scanner
var orderedScanners []string
// RegisterScan registers each individual scanner to be ran by the framework
func RegisterScan(name string, s Scanner) {
//add to list and map
if scanners[name] != nil {
log.Fatalf("name: %s already used", name)
}
orderedScanners = append(orderedScanners, name)
scanners[name] = &s
}
// PrintScanners prints all registered scanners
func PrintScanners() {
for k, v := range scanners {
fmt.Println(k, v)
}
}
// RunScanner runs a single scan on a target and returns the resulting data
func RunScanner(s Scanner, mon *Monitor, target ScanTarget) (string, ScanResponse) {
t := time.Now()
status, res, e := s.Scan(target)
var err *string
if e == nil {
mon.statusesChan <- moduleStatus{name: s.GetName(), st: statusSuccess}
err = nil
} else {
mon.statusesChan <- moduleStatus{name: s.GetName(), st: statusFailure}
errString := e.Error()
err = &errString
}
resp := ScanResponse{Result: res, Protocol: s.Protocol(), Error: err, Timestamp: t.Format(time.RFC3339), Status: status}
return s.GetName(), resp
}
func init() {
scanners = make(map[string]*Scanner)
}