-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathassociateddomains.go
65 lines (58 loc) · 1.62 KB
/
associateddomains.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
package main
import (
"encoding/json"
"fmt"
"strconv"
"sync"
)
type Meta struct {
Pages int `json:"total_pages"`
Query string `json:"query"`
Page int `json:"page"`
MaxPage int `json:"max_page"`
}
func associatedDomains(work chan string, wg *sync.WaitGroup) {
defer wg.Done()
for text := range work {
printAllPages(text) // text is the domain
}
}
func printAllPages(domain string) {
response := getResponse("GET", "domain/"+domain+"/associated", "")
var results map[string]interface{}
json.Unmarshal([]byte(response), &results)
metaInterface, ok := results["meta"].(map[string]interface{})
if !ok { // no results
if output == "list" {
return
} else {
fmt.Println(response)
}
return
}
maxPage := metaInterface["max_page"].(float64) // total number of pages
if output == "list" {
parseAndPrintDomains(response) // print the first page
// print all the other pages
for i := 2; i <= int(maxPage); i++ {
response = getResponse("GET", "domain/"+domain+"/associated?page="+strconv.Itoa(i), "")
parseAndPrintDomains(response)
}
} else {
fmt.Println(response) // print the first page
// print all the other pages
for i := 2; i <= int(maxPage); i++ {
response = getResponse("GET", "domain/"+domain+"/associated?page="+strconv.Itoa(i), "")
fmt.Println(response)
}
}
}
func parseAndPrintDomains(body string) {
var results map[string]interface{}
json.Unmarshal([]byte(body), &results)
recordInterfaces := results["records"].([]interface{})
for _, record := range recordInterfaces {
recordMap := record.(map[string]interface{})
fmt.Println(recordMap["hostname"].(string))
}
}