-
Notifications
You must be signed in to change notification settings - Fork 4
/
crtsh.go
70 lines (62 loc) · 2.13 KB
/
crtsh.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
)
type Certificate struct {
CommonName string `json:"common_name"`
NameValue string `json:"name_value"`
}
func main() {
// Check if input is coming from a pipe or file
fi, _ := os.Stdin.Stat()
if (fi.Mode() & os.ModeCharDevice) == 0 {
// input is coming from a pipe or file
bytes, _ := ioutil.ReadAll(os.Stdin)
input := string(bytes)
// Iterate over each line of input
for _, domain := range strings.Split(input, "\n") {
// Skip empty lines
if domain == "" {
continue
}
url := fmt.Sprintf("https://crt.sh/?q=%%25.%s&output=json", domain)
response, err := http.Get(url)
if err != nil {
fmt.Printf("The HTTP request for %s failed with error %s\n", domain, err)
} else {
data, _ := ioutil.ReadAll(response.Body)
var certificates []Certificate
json.Unmarshal(data, &certificates)
for _, certificate := range certificates {
fmt.Println(certificate.CommonName)
fmt.Println(certificate.NameValue)
}
}
}
} else {
// input is coming from command line
if len(os.Args) < 2 {
fmt.Println("Please provide a domain name")
return
}
domain := os.Args[1]
url := fmt.Sprintf("https://crt.sh/?q=%%25.%s&output=json", domain)
response, err := http.Get(url)
if err != nil {
fmt.Printf("The HTTP request for %s failed with error %s\n", domain, err)
} else {
data, _ := ioutil.ReadAll(response.Body)
var certificates []Certificate
json.Unmarshal(data, &certificates)
for _, certificate := range certificates {
fmt.Println(certificate.CommonName)
fmt.Println(certificate.NameValue)
}
}
}
}