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

Change WithTargetExclusion to a variadic function #132

Merged
merged 1 commit into from
Aug 2, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions optionsTargetSpecification.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nmap

import (
"fmt"
"strings"
)

// WithTargets sets the target of a scanner.
Expand All @@ -11,11 +12,13 @@ func WithTargets(targets ...string) Option {
}
}

// WithTargetExclusion sets the excluded targets of a scanner.
func WithTargetExclusion(target string) Option {
// WithTargetExclusions sets the excluded targets of a scanner.
func WithTargetExclusions(targets ...string) Option {
targetList := strings.Join(targets, ",")

return func(s *Scanner) {
s.args = append(s.args, "--exclude")
s.args = append(s.args, target)
s.args = append(s.args, targetList)
}
}

Expand Down
2 changes: 1 addition & 1 deletion optionsTargetSpecification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestTargetSpecification(t *testing.T) {
description: "target exclusion",

options: []Option{
WithTargetExclusion("192.168.0.1,172.16.100.0/24"),
WithTargetExclusions("192.168.0.1", "172.16.100.0/24"),
},

expectedArgs: []string{
Expand Down
Loading