From 7095be0d7854ccb0fba660fa86f61c2dfbf4fdd3 Mon Sep 17 00:00:00 2001 From: sonia Date: Sun, 16 Apr 2023 14:51:09 +0330 Subject: [PATCH] fixed undefined type --- golang/go.mod | 6 +++--- golang/go.sum | 12 ++++++------ golang/scanner/{scanner.go => scan.go} | 22 +++++++++------------- golang/scanner/types.go | 4 ++-- 4 files changed, 20 insertions(+), 24 deletions(-) rename golang/scanner/{scanner.go => scan.go} (96%) diff --git a/golang/go.mod b/golang/go.mod index 14d208bc..34c71d7f 100644 --- a/golang/go.mod +++ b/golang/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203 - github.com/spf13/cobra v1.6.1 + github.com/spf13/cobra v1.7.0 github.com/xtls/xray-core v1.8.0 ) @@ -19,7 +19,7 @@ require ( github.com/google/btree v1.1.2 // indirect github.com/google/pprof v0.0.0-20230228050547-1710fef4ab10 // indirect github.com/gorilla/websocket v1.5.0 // indirect - github.com/inconshreveable/mousetrap v1.0.1 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/klauspost/compress v1.16.0 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/miekg/dns v1.1.51 // indirect @@ -44,7 +44,7 @@ require ( golang.org/x/exp v0.0.0-20230307190834-24139beb5833 // indirect golang.org/x/mod v0.9.0 // indirect golang.org/x/net v0.8.0 // indirect - golang.org/x/sys v0.7.0 // indirect + golang.org/x/sys v0.6.0 // indirect golang.org/x/text v0.8.0 // indirect golang.org/x/time v0.3.0 // indirect golang.org/x/tools v0.7.0 // indirect diff --git a/golang/go.sum b/golang/go.sum index c5394797..027883b0 100644 --- a/golang/go.sum +++ b/golang/go.sum @@ -87,8 +87,8 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= -github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= -github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= @@ -175,8 +175,8 @@ github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYED github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw= github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE= github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= -github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= -github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= +github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= +github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -267,8 +267,8 @@ golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= -golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= diff --git a/golang/scanner/scanner.go b/golang/scanner/scan.go similarity index 96% rename from golang/scanner/scanner.go rename to golang/scanner/scan.go index a1d08954..ee76da1d 100644 --- a/golang/scanner/scanner.go +++ b/golang/scanner/scan.go @@ -1,6 +1,5 @@ package scanner -import "C" import ( config "CFScanner/configuration" "CFScanner/logger" @@ -8,7 +7,6 @@ import ( "CFScanner/utils" "CFScanner/vpn" "fmt" - "github.com/eiannone/keyboard" "math" "os" "runtime" @@ -16,6 +14,8 @@ import ( "strings" "sync" "time" + + "github.com/eiannone/keyboard" ) var results [][]string @@ -27,7 +27,7 @@ var ( uploadLatency float64 ) -type Result struct { +type ScanResult struct { IP string Download struct { Speed []float64 @@ -46,9 +46,9 @@ var ( ) // const WorkerCount = 48 -func scanner(ip string, Config config.Configuration, Worker config.Worker) *Result { +func scanner(ip string, Config config.Configuration, Worker config.Worker) *ScanResult { - result := &Result{ + result := &ScanResult{ IP: ip, } @@ -67,11 +67,7 @@ func scanner(ip string, Config config.Configuration, Worker config.Worker) *Resu proxies = vpn.ProxyBind(listen, port) // wait for port - waitPort := utils.WaitForPort(listen, port, time.Duration(5)) - - if waitPort != nil { - fmt.Errorf(waitPort.Error()) - } + utils.WaitForPort(listen, port, time.Duration(5)) var err error process = vpn.XRayInstance(xrayConfigPath) @@ -142,7 +138,7 @@ func scanner(ip string, Config config.Configuration, Worker config.Worker) *Resu return result } -func uploader(ip string, Upload *config.Upload, proxies map[string]string, result *Result) (*Result, bool) { +func uploader(ip string, Upload *config.Upload, proxies map[string]string, result *ScanResult) (*ScanResult, bool) { var err error nBytes := Upload.MinUlSpeed * 1000 * Upload.MaxUlTime uploadSpeed, uploadLatency, err = speedtest.UploadSpeedTest(int(nBytes), proxies, @@ -188,7 +184,7 @@ func uploader(ip string, Upload *config.Upload, proxies map[string]string, resul return nil, false } -func downloader(ip string, Download *config.Download, proxies map[string]string, result *Result) (*Result, bool) { +func downloader(ip string, Download *config.Download, proxies map[string]string, result *ScanResult) (*ScanResult, bool) { nBytes := Download.MinDlSpeed * 1000 * Download.MaxDlTime var err error @@ -312,7 +308,7 @@ func scan(Config *config.Configuration, worker *config.Worker, ip string) { MeanUploadLatency: meanUploadLatency, } default: - cause := fmt.Errorf("Invalid writer type: %s\n", Config.Config.Writer) + cause := fmt.Errorf("invalid writer type: %s", Config.Config.Writer) ld := logger.ScannerManage{ IP: "", Status: logger.ErrorStatus, diff --git a/golang/scanner/types.go b/golang/scanner/types.go index 48c953f3..f2a44564 100644 --- a/golang/scanner/types.go +++ b/golang/scanner/types.go @@ -6,7 +6,7 @@ type Writer interface { } type CSV struct { - res *Result + res *ScanResult IP string DownloadMeanJitter float64 UploadMeanJitter float64 @@ -17,7 +17,7 @@ type CSV struct { } type JSON struct { - res *Result + res *ScanResult IP string `json:"ip"` DownloadMeanJitter float64 `json:"downloadMeanJitter"` UploadMeanJitter float64 `json:"uploadMeanJitter"`