package main
import (
"fmt"
"crypto/tls"
"time"
)
func main() {
domains := []string{
"www.dominic-ricottone.com",
"git.dominic-ricottone.com",
"www.intra.dominic-ricottone.com",
"media.intra.dominic-ricottone.com",
}
longest := 0
for _, d := range domains {
if longest < len(d) {
longest = len(d)
}
}
for _, d := range domains {
fmt.Printf("%*s: ", longest, d)
// I'm only ever going to care about real HTTPS certs,
// so I am hardcoding the port
name := d + ":443"
conn, err := tls.Dial("tcp", name, nil)
if err != nil {
fmt.Println("No certificate found")
continue
}
expiry := conn.ConnectionState().PeerCertificates[0].NotAfter
timestamp := expiry.Format("Monday, January 2")
days := int(time.Until(expiry).Hours() / 24)
if days < 0 {
fmt.Println("Expired")
} else if days < 1 {
fmt.Println("Expiring today")
} else if days < 2 {
fmt.Println("Valid for 1 day\n")
} else {
fmt.Printf("Valid for %d days (until %s)\n", days, timestamp)
}
}
}