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
|
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
|
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
|
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
|
## 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
|
```bash
|
||||||
$ cat sites.txt
|
$ cat sites.txt
|
||||||
apple.com
|
apple.com
|
||||||
|
50
main.go
50
main.go
@ -18,24 +18,13 @@ var conc = flag.Int("workers", 8, "number of fetches to perform concurrently")
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
work := make(chan job)
|
work := make(chan job)
|
||||||
go func() {
|
if len(flag.Args()) > 0 {
|
||||||
s := bufio.NewScanner(os.Stdin)
|
go fromArgs(work, flag.Args())
|
||||||
for s.Scan() {
|
} else {
|
||||||
line := s.Text()
|
go fromStdin(work)
|
||||||
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)
|
|
||||||
}()
|
|
||||||
|
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
sema := make(chan bool, *conc)
|
sema := make(chan bool, *conc)
|
||||||
@ -59,6 +48,33 @@ func main() {
|
|||||||
wg.Wait()
|
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 {
|
type job struct {
|
||||||
host string
|
host string
|
||||||
port string
|
port string
|
||||||
|
Loading…
Reference in New Issue
Block a user