Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --unique and --script-timeout flags #99

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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