-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
82 lines (67 loc) · 1.84 KB
/
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"bufio"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"regexp"
"strings"
"time"
)
// Sets the connection timeout to 20 seconds
var httpClient = &http.Client{Timeout: 20 * time.Second}
/**
* Checks if a slice or an array contains an item
* ( there is no build-in function in Go )
*/
func contains(s []string, str string) bool {
for _, v := range s {
if v == str {
return true
}
}
return false
}
func main() {
// Array that holds unique domains
domainList := []string{}
// Inits reader
reader := bufio.NewReader(os.Stdin)
fmt.Print("Type domain: ")
userInput, _ := reader.ReadString('\n')
// Converts CRLF to LF
userInput = strings.Replace(userInput, "\n", "", -1)
res, err := httpClient.Get("https://crt.sh/?dNSName=" + userInput)
if err != nil {
log.Fatalln(err)
}
defer res.Body.Close()
// The pattern finds domains in the HTML code
pattern := "<TD>(.+)</TD>"
body, err := ioutil.ReadAll(res.Body)
// Splits HTML body string to an array of strings
rows := strings.Split(string(body), "\n")
// Sets pattern for domains tag
ms := regexp.MustCompile(`<TD>(.+)</TD>`)
for _, row := range rows {
match, _ := regexp.MatchString(pattern, row)
// If the tag found and string does not contain style attribute
if match && !strings.Contains(row, "style=") {
// Splits the string into an array of strings that holds domains
domains := strings.Split(ms.ReplaceAllString(row, "$1"), "<BR>")
for _, domain := range domains {
// Removes wildcard (*.), trim whitespace and lowercase
domain := strings.ToLower(strings.TrimSpace(strings.Replace(domain, "*.", "", -1)))
// Checks if the domain is already added
if !contains(domainList, domain) {
// Prints domain
fmt.Println(">> " + domain)
// Appends domain to domain list
domainList = append(domainList, domain)
}
}
}
}
}