Created
December 31, 2013 20:27
-
-
Save tomsteele/8201885 to your computer and use it in GitHub Desktop.
Prints "NotAfter" field of a certificate for each host in tls.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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