From 4cca4e794cdfc244f1017010f0f73c75269fc1ef Mon Sep 17 00:00:00 2001 From: Sonya Date: Thu, 11 May 2023 12:14:56 +0330 Subject: [PATCH] fixed windows directory creation updated save result func to updated with every hit instead of sorting after scanning all ip's --- golang/configuration/config.go | 4 ++-- golang/scanner/scan.go | 14 ++++++++------ golang/utils/utils.go | 2 ++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/golang/configuration/config.go b/golang/configuration/config.go index 1ca7f03f..3d8bb85d 100644 --- a/golang/configuration/config.go +++ b/golang/configuration/config.go @@ -13,10 +13,10 @@ import ( ) var ( - PROGRAMDIR = filepath.Dir(os.Args[0]) + PROGRAMDIR, _ = filepath.Abs(filepath.Dir(os.Args[0])) DIR = filepath.Join(PROGRAMDIR, "config") RESULTDIR = filepath.Join(PROGRAMDIR, "result") - StartDtStr = time.Now().Format("2006-01-02_15:04:05") + StartDtStr = time.Now().Format("2006-01-02_15-04-05") CSVInterimResultsPath = filepath.Join(RESULTDIR, StartDtStr+"_result.csv") JSONInterimResultsPath = filepath.Join(RESULTDIR, StartDtStr+"_result.json") FinalResultsPathSorted = filepath.Join(RESULTDIR, StartDtStr+"_final.txt") diff --git a/golang/scanner/scan.go b/golang/scanner/scan.go index ee76da1d..67744e7d 100644 --- a/golang/scanner/scan.go +++ b/golang/scanner/scan.go @@ -46,6 +46,7 @@ var ( ) // const WorkerCount = 48 + func scanner(ip string, Config config.Configuration, Worker config.Worker) *ScanResult { result := &ScanResult{ @@ -323,6 +324,13 @@ func scan(Config *config.Configuration, worker *config.Worker, ip string) { Writer.Output() Writer.Write() + // Save results & sort based on download latency + err := saveResults(results, config.FinalResultsPathSorted, true) + if err != nil { + fmt.Println(err) + return + } + } func Start(C config.Configuration, Worker config.Worker, ipList []string, threadsCount int) { var ( @@ -398,12 +406,6 @@ func Start(C config.Configuration, Worker config.Worker, ipList []string, thread _ = keyboard.Close() }() - // Save results - err = saveResults(results, config.FinalResultsPathSorted, true) - if err != nil { - fmt.Println(err) - return - } } // controller is a event listener for pausing or running workers diff --git a/golang/utils/utils.go b/golang/utils/utils.go index ad607162..f04e3c99 100644 --- a/golang/utils/utils.go +++ b/golang/utils/utils.go @@ -8,6 +8,7 @@ import ( "net" "net/url" "os" + "path/filepath" "strconv" "strings" "time" @@ -32,6 +33,7 @@ func Round(val float64, roundOn float64, places int) (newVal float64) { } func CreateDir(dirPath string) { + dirPath = filepath.FromSlash(dirPath) if _, err := os.Stat(dirPath); os.IsNotExist(err) { err := os.MkdirAll(dirPath, 0755) if err != nil {