-
Notifications
You must be signed in to change notification settings - Fork 60
/
subdomains.go
44 lines (40 loc) · 1.02 KB
/
subdomains.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
package main
import (
"encoding/json"
"fmt"
"sync"
)
// the main subdomains function
func subdomains(work chan string, wg *sync.WaitGroup) {
defer wg.Done()
for text := range work {
retrieveAndPrintSubdomains(text)
}
}
// get the subdomains + print them
func retrieveAndPrintSubdomains(domain string) {
response := getResponse("GET", "domain/"+domain+"/subdomains", "")
if output == "json" {
fmt.Println(response)
} else {
parseAndPrintSubdomains(response, domain)
}
}
// list the subdomains
func parseAndPrintSubdomains(body string, domain string) {
// don't try to parse the body if it is empty
if body == "" {
return
}
var results map[string]interface{}
json.Unmarshal([]byte(body), &results)
val, ok := results["subdomains"]
// Check if there are subdomains in the request to avoid the interface conversion panic
if !ok || val == nil {
return
}
subdomainInterfaces := results["subdomains"].([]interface{})
for _, subdomain := range subdomainInterfaces {
fmt.Println(subdomain.(string) + "." + domain)
}
}