Skip to content

Instantly share code, notes, and snippets.

@tomsteele
Created December 31, 2013 20:27
Show Gist options
  • Save tomsteele/8201885 to your computer and use it in GitHub Desktop.
Save tomsteele/8201885 to your computer and use it in GitHub Desktop.
Prints "NotAfter" field of a certificate for each host in tls.txt
package main
import (
"bufio"
"crypto/tls"
"time"
"net"
"fmt"
"os"
)
func main() {
file, err := os.Open("tls.txt")
if err != nil {
panic(err)
}
defer file.Close()
hosts := []string{}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
hosts = append(hosts, scanner.Text())
}
if scanner.Err() != nil {
panic("error")
}
for _, h := range hosts {
tconn, err := net.DialTimeout("tcp", h, 600*time.Millisecond)
if err != nil {
continue
}
conn := tls.Client(tconn, &tls.Config{InsecureSkipVerify: true})
defer conn.Close()
if err := conn.Handshake(); err != nil {
continue
}
state := conn.ConnectionState()
cert := state.PeerCertificates[0]
fmt.Println(h, "\nNot valid after:", cert.NotAfter)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment