Skip to content

Commit

Permalink
Add --unique and --script-timeout flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Ullaakut committed Jul 22, 2022
1 parent 1b0b513 commit b9ef145
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion iflist_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package nmap

import (
"github.com/stretchr/testify/assert"
"net"
"testing"

"github.com/stretchr/testify/assert"
)

func TestScanner_GetInterfaceList(t *testing.T) {
Expand Down
21 changes: 21 additions & 0 deletions nmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,17 @@ func WithRandomTargets(randomTargets int) Option {
}
}

// WithUnique makes each address be scanned only once.
// The default behavior is to scan each address as many times
// as it is specified in the target list, such as when network
// ranges overlap or different hostnames resolve to the same
// address.
func WithUnique() Option {
return func(s *Scanner) {
s.args = append(s.args, "--unique")
}
}

/*** Host discovery ***/

// WithListScan sets the discovery mode to simply list the targets to scan and not scan them.
Expand Down Expand Up @@ -1075,6 +1086,16 @@ func WithScriptUpdateDB() Option {
}
}

// WithScriptTimeout sets the script timeout.
func WithScriptTimeout(timeout time.Duration) Option {
milliseconds := timeout.Round(time.Nanosecond).Nanoseconds() / 1000000

return func(s *Scanner) {
s.args = append(s.args, "--script-timeout")
s.args = append(s.args, fmt.Sprintf("%dms", int(milliseconds)))
}
}

/*** OS Detection ***/

// WithOSDetection enables OS detection.
Expand Down
23 changes: 23 additions & 0 deletions nmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,17 @@ func TestTargetSpecification(t *testing.T) {
"4",
},
},
{
description: "unique addresses",

options: []Option{
WithUnique(),
},

expectedArgs: []string{
"--unique",
},
},
{
description: "target exclusion",

Expand Down Expand Up @@ -1341,6 +1352,18 @@ func TestScriptScan(t *testing.T) {
"--script-updatedb",
},
},
{
description: "set script timeout",

options: []Option{
WithScriptTimeout(40 * time.Second),
},

expectedArgs: []string{
"--script-timeout",
"40000ms",
},
},
}

for _, test := range tests {
Expand Down

0 comments on commit b9ef145

Please sign in to comment.