-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (40 loc) · 852 Bytes
/
main.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
package main
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
)
type CrtshResult struct {
Domain string `json:"name_value"`
}
func main() {
if len(os.Args) < 2 {
fmt.Println("Command takes an argument of domain")
os.Exit(1)
}
da := os.Args[1]
fmt.Println(da)
res, err := http.Get(fmt.Sprintf("https://crt.sh/?q=%%25.%s&output=json", da))
if err != nil {
log.Fatal("Http ERROR:", err)
}
fmt.Println(res.StatusCode)
body, err := io.ReadAll(res.Body)
defer res.Body.Close()
if res.StatusCode > 299 {
log.Fatalf("Response failed with status code %d, and body: %s\n", res.StatusCode, body)
}
if err != nil {
log.Fatal(err)
}
// var output []string
var result []CrtshResult
json.Unmarshal(body, &result)
for _, d := range result {
// output = append(output, d.Domain)
fmt.Println(d.Domain)
}
}