From ceb3133e798a49b17a10fdc77b0e05f5cc40fc9f Mon Sep 17 00:00:00 2001 From: Francesco Boscarino Date: Wed, 13 Mar 2019 11:09:49 +0100 Subject: [PATCH 1/6] Correct bug on passing parameters to scan thread which prevents to fill correctly the results --- pkg/scanner/scanner.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/scanner/scanner.go b/pkg/scanner/scanner.go index 38d8ee4..1d78d27 100644 --- a/pkg/scanner/scanner.go +++ b/pkg/scanner/scanner.go @@ -106,10 +106,9 @@ func (s *Scanner) Scan() []AddressSet { for _, ip := range s.ips { for _, port := range s.ports { for _, proto := range s.protocols { - addr := fmt.Sprintf("%s:%d", ip, port) - wg.Add(1) - go func(proto, addr string) { + go func(ip net.IP, port int, proto string) { + addr := fmt.Sprintf("%s:%d", ip, port) defer wg.Done() guard <- struct{}{} @@ -125,7 +124,7 @@ func (s *Scanner) Scan() []AddressSet { }) resultsMutex.Unlock() } - }(proto, addr) + }(ip, port, proto) } } } From 1783e9beaeff7d96e8c3b1d2360e7f9b35bb4f16 Mon Sep 17 00:00:00 2001 From: Francesco Boscarino Date: Wed, 13 Mar 2019 12:23:22 +0100 Subject: [PATCH 2/6] Better handling of parallel thread --- pkg/scanner/scanner.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/scanner/scanner.go b/pkg/scanner/scanner.go index 1d78d27..3f68790 100644 --- a/pkg/scanner/scanner.go +++ b/pkg/scanner/scanner.go @@ -106,14 +106,13 @@ func (s *Scanner) Scan() []AddressSet { for _, ip := range s.ips { for _, port := range s.ports { for _, proto := range s.protocols { + guard <- struct{}{} wg.Add(1) go func(ip net.IP, port int, proto string) { addr := fmt.Sprintf("%s:%d", ip, port) defer wg.Done() - guard <- struct{}{} c, err := net.DialTimeout(proto, addr, s.timeout) - <-guard if err == nil { c.Close() resultsMutex.Lock() @@ -124,6 +123,7 @@ func (s *Scanner) Scan() []AddressSet { }) resultsMutex.Unlock() } + <-guard }(ip, port, proto) } } From 8e40a8dd0606e553511851cbd18a99749698bc69 Mon Sep 17 00:00:00 2001 From: Francesco Boscarino Date: Sat, 19 Feb 2022 13:07:45 +0100 Subject: [PATCH 3/6] Update go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index c95caa2..39696f9 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/jessfraz/netscan +module github.com/bizmate-oss/netscan require ( github.com/davecgh/go-spew v1.1.1 // indirect From 057a3f9bd31cf4514ad4461670ea0e31bcf0418b Mon Sep 17 00:00:00 2001 From: Francesco Boscarino Date: Sat, 19 Feb 2022 13:18:52 +0100 Subject: [PATCH 4/6] Update reference --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index b3dc45c..00031a4 100644 --- a/main.go +++ b/main.go @@ -13,8 +13,8 @@ import ( "time" "github.com/genuinetools/pkg/cli" - "github.com/jessfraz/netscan/pkg/scanner" - "github.com/jessfraz/netscan/version" + "github.com/bizmate-oss/netscan/pkg/scanner" + "github.com/bizmate-oss/netscan/version" "github.com/sirupsen/logrus" ) From 2b65d8edcdff7cf8798e8bf3ccfdf92e62a344cf Mon Sep 17 00:00:00 2001 From: Francesco Boscarino Date: Sat, 19 Feb 2022 13:19:35 +0100 Subject: [PATCH 5/6] Update main.go --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index b3dc45c..00031a4 100644 --- a/main.go +++ b/main.go @@ -13,8 +13,8 @@ import ( "time" "github.com/genuinetools/pkg/cli" - "github.com/jessfraz/netscan/pkg/scanner" - "github.com/jessfraz/netscan/version" + "github.com/bizmate-oss/netscan/pkg/scanner" + "github.com/bizmate-oss/netscan/version" "github.com/sirupsen/logrus" ) From a318657e05e2d117508d1a45b10d86e0db1684db Mon Sep 17 00:00:00 2001 From: Francesco Boscarino Date: Sat, 19 Feb 2022 15:01:22 +0100 Subject: [PATCH 6/6] Update go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 39696f9..c95caa2 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/bizmate-oss/netscan +module github.com/jessfraz/netscan require ( github.com/davecgh/go-spew v1.1.1 // indirect