diff --git a/LICENSE b/LICENSE index 340187d..5996d0b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ MIT License -Copyright (c) 2017 Stephen McQuay +Copyright (c) 2018 Stephen McQuay Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/README.md b/README.md index 43ebfd2..3089f8c 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,15 @@ $ echo | openssl s_client -connect $hostname:$port 2> /dev/null | openssl x509 - ## example usage +```bash +$ certexp google.com amazon.com imap.gmail.com:993 +google.com:443 2018-03-07 13:01:00 +0000 UTC +imap.gmail.com:993 2018-03-07 13:02:00 +0000 UTC +amazon.com:443 2018-09-21 23:59:59 +0000 UTC +``` + +or to stdin: + ```bash $ cat sites.txt apple.com diff --git a/main.go b/main.go index 27fdf15..1976ede 100644 --- a/main.go +++ b/main.go @@ -18,24 +18,13 @@ var conc = flag.Int("workers", 8, "number of fetches to perform concurrently") func main() { flag.Parse() + work := make(chan job) - go func() { - s := bufio.NewScanner(os.Stdin) - for s.Scan() { - line := s.Text() - if line == "" { - continue - } - - host, port := line, "443" - if h, p, err := net.SplitHostPort(line); err == nil { - host, port = h, p - } - - work <- job{host, port} - } - close(work) - }() + if len(flag.Args()) > 0 { + go fromArgs(work, flag.Args()) + } else { + go fromStdin(work) + } wg := sync.WaitGroup{} sema := make(chan bool, *conc) @@ -59,6 +48,33 @@ func main() { wg.Wait() } +func parseLine(line string) job { + host, port := line, "443" + if h, p, err := net.SplitHostPort(line); err == nil { + host, port = h, p + } + return job{host, port} +} + +func fromArgs(work chan job, args []string) { + for _, arg := range args { + work <- parseLine(arg) + } + close(work) +} + +func fromStdin(work chan job) { + s := bufio.NewScanner(os.Stdin) + for s.Scan() { + line := s.Text() + if line == "" { + continue + } + work <- parseLine(line) + } + close(work) +} + type job struct { host string port string