From d1cd0e550d532169f85fa1e6b8ed7001740e05a5 Mon Sep 17 00:00:00 2001 From: 4shen0ne <4shen.01@gmail.com> Date: Thu, 1 Aug 2024 10:50:09 +0800 Subject: [PATCH] Change WithTargetExclusion to a variadic function --- optionsTargetSpecification.go | 9 ++++++--- optionsTargetSpecification_test.go | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/optionsTargetSpecification.go b/optionsTargetSpecification.go index 190214c..f86de5e 100644 --- a/optionsTargetSpecification.go +++ b/optionsTargetSpecification.go @@ -2,6 +2,7 @@ package nmap import ( "fmt" + "strings" ) // WithTargets sets the target of a scanner. @@ -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) } } diff --git a/optionsTargetSpecification_test.go b/optionsTargetSpecification_test.go index ca49462..2096625 100644 --- a/optionsTargetSpecification_test.go +++ b/optionsTargetSpecification_test.go @@ -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{