Allow user to specify hostnames as argv
This commit is contained in:
parent
dfd733ff9d
commit
b4abcd1abf
2
LICENSE
2
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
|
||||
|
@ -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
|
||||
|
48
main.go
48
main.go
@ -18,25 +18,14 @@ 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
|
||||
if len(flag.Args()) > 0 {
|
||||
go fromArgs(work, flag.Args())
|
||||
} else {
|
||||
go fromStdin(work)
|
||||
}
|
||||
|
||||
host, port := line, "443"
|
||||
if h, p, err := net.SplitHostPort(line); err == nil {
|
||||
host, port = h, p
|
||||
}
|
||||
|
||||
work <- job{host, port}
|
||||
}
|
||||
close(work)
|
||||
}()
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
sema := make(chan bool, *conc)
|
||||
for w := range work {
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user