-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoptions.go
69 lines (64 loc) · 1.3 KB
/
options.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
69
package scanner
import (
"runtime"
"strings"
"time"
)
const (
MethodSYN = "syn"
MethodConnect = "connect"
)
type Options struct {
// "syn", "connect"
Method string
Device string
Rate int
Timeout time.Duration
// "connect": connectScanner() goroutine number
// "syn": synScanner() and synParser() goroutine number
Workers int
// packetSender number useless for "connect"
Senders int
// if true scanner will not handle duplicate result,
// it will use less memory
// default will handle duplicate result
Raw bool
}
func (opt *Options) apply() {
if opt.Method == "" {
opt.Method = MethodSYN
}
if opt.Rate < 1 {
opt.Rate = 1000
}
if opt.Timeout < 1 {
switch opt.Method {
case MethodConnect:
opt.Timeout = 5 * time.Second
case MethodSYN:
opt.Timeout = 3 * time.Second
}
}
if opt.Workers < 1 {
switch opt.Method {
case MethodConnect:
opt.Workers = 64 * runtime.NumCPU()
case MethodSYN:
opt.Workers = 32 * runtime.NumCPU()
}
}
if opt.Senders < 1 {
switch runtime.GOOS {
case "windows":
opt.Senders = 2 // "magic send packet speed"
case "linux":
opt.Senders = 1 // "one goroutine will get full speed"
default:
opt.Senders = 1
}
}
}
func split(str string) []string {
str = strings.Replace(str, " ", "", -1)
return strings.Split(str, ",")
}