From 74a1013c192b569b78b66a9ea325cd8d47e68601 Mon Sep 17 00:00:00 2001 From: Sascha Monteiro Date: Sat, 27 Jul 2024 13:05:50 +1200 Subject: [PATCH] added few tests --- README.md | 24 +++++++++++++++++++++++- internal/output/output.go | 9 +++++++-- main.go | 8 +++++++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e8c287b..207edb9 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,28 @@ A utility to scan for TLS certificates in a network segment in CIDR format to qu This is written in GO and the assets are currently only build for Linux amd64. -The concurrency for host cert checking is currently set to 128. +The concurrency for host cert checking is currently set to 128, tested 1024 which is faster. ## Usage + +### Command Flags +``` +Usage information: + -cidr string + network cidr list (default "192.168.10.0/24,192.168.11.0/24") + -conc int + concurrent connections (default 128) + -html string + html output file + -json string + json output file + -ports string + tcp port list (default "443,636,587,8443") + -skipnodns + skip no dns found + -v version +``` + ### Linux amd64 ``` #single subnet, single port, output to console only @@ -21,6 +40,9 @@ The concurrency for host cert checking is currently set to 128. #multiple subnets, multiple ports, output to console only ./certchecker_linux -cidr=10.10.10.0/24,10.10.20.0/24 -ports=443,8443 + +#multiple subnets, multiple ports, output to console only, 1024 concurrent checks +./certchecker_linux -cidr=10.10.10.0/24,10.10.20.0/24 -ports=443,8443 -conc=1024 ``` ## Output ### Console diff --git a/internal/output/output.go b/internal/output/output.go index 9327c03..068e3e2 100644 --- a/internal/output/output.go +++ b/internal/output/output.go @@ -73,7 +73,7 @@ func CreateOutFile(data []certs.TlsCert, fileName string, templateFile string, A fmt.Printf("error execute template: %v\n", err) return } - + fmt.Printf("Output file created: %s\n", fileName) } // JsonMeta holds the metadata @@ -99,7 +99,12 @@ func CreateJsonFile(data []certs.TlsCert, fileName string) { fmt.Println("error parsing data to json: ", err) return } - f.Write(jsonData) + _, err = f.Write(jsonData) + if err != nil { + fmt.Println("error writing data to file: ", err) + return + } + fmt.Printf("Output file created: %s\n", fileName) } // exp formats the expired status diff --git a/main.go b/main.go index e022d90..c785f8f 100644 --- a/main.go +++ b/main.go @@ -17,13 +17,19 @@ var buildTime string func main() { + flag.Usage = func() { + fmt.Fprintf(flag.CommandLine.Output(), "Cert Checker git-sha1:%v buildtime:%v\n", sha1ver, buildTime) + fmt.Fprintf(flag.CommandLine.Output(), "Usage information:\n") + flag.PrintDefaults() + } + cidrAddressList := flag.String("cidr", "192.168.10.0/24,192.168.11.0/24", "network cidr list") portList := flag.String("ports", "443,636,587,8443", "tcp port list") skipNoDnsFound := flag.Bool("skipnodns", false, "skip no dns found") htmlOut := flag.String("html", "", "html output file") jsonOut := flag.String("json", "", "json output file") concurrent := flag.Int("conc", 128, "concurrent connections") - ver := flag.Bool("v", false, fmt.Sprintf("version (sha:%s buildtime:%s)", sha1ver, buildTime)) + ver := flag.Bool("v", false, "version") flag.Parse() if *ver { fmt.Printf("version: %s\n", sha1ver)