-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtlx.go
54 lines (42 loc) · 948 Bytes
/
tlx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"crypto/tls"
"fmt"
"time"
go_arg "github.com/alexflint/go-arg"
)
const (
DayFormat string = "2006-01-02 15:04 MST"
Version string = "1.0.0"
)
type args struct {
Domain string `arg:"required,positional"`
Port string `arg:"positional" default:"443"`
}
func (args) Version() string {
return "tlx " + Version
}
func main() {
now := time.Now()
var args args
go_arg.MustParse(&args)
tls_config := &tls.Config{InsecureSkipVerify: true}
conn, err := tls.Dial("tcp", args.Domain+":"+args.Port, tls_config)
if err != nil {
panic(err)
}
defer conn.Close()
cert := conn.ConnectionState().PeerCertificates[0]
domain := cert.Subject.String()[3:]
expireDate, err := time.Parse(DayFormat, cert.NotAfter.Format(DayFormat))
if err != nil {
panic(err)
}
days := expireDate.Sub(now).Hours() / 24
fmt.Printf(
"%s expires %s (in %.0f days)\n",
domain,
cert.NotAfter.Format(DayFormat),
days,
)
}