forked from tomnomnom/assetfinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
urlscan.go
59 lines (47 loc) · 956 Bytes
/
urlscan.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
package main
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
)
func fetchUrlscan(domain string) ([]string, error) {
resp, err := http.Get(
fmt.Sprintf("https://urlscan.io/api/v1/search/?q=domain:%s", domain),
)
if err != nil {
return []string{}, err
}
defer resp.Body.Close()
output := make([]string, 0)
dec := json.NewDecoder(resp.Body)
wrapper := struct {
Results []struct {
Task struct {
URL string `json:"url"`
} `json:"task"`
Page struct {
URL string `json:"url"`
} `json:"page"`
} `json:"results"`
}{}
err = dec.Decode(&wrapper)
if err != nil {
return []string{}, err
}
for _, r := range wrapper.Results {
u, err := url.Parse(r.Task.URL)
if err != nil {
continue
}
output = append(output, u.Hostname())
}
for _, r := range wrapper.Results {
u, err := url.Parse(r.Page.URL)
if err != nil {
continue
}
output = append(output, u.Hostname())
}
return output, nil
}