/
bing.go
56 lines (46 loc) · 1.25 KB
/
bing.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
// Copyright 2017 Jeff Foley. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package sources
import (
"log"
"net/url"
"strconv"
"time"
"github.com/caffix/amass/amass/internal/utils"
)
const (
BingSourceString string = "Bing Scrape"
bingQuantity int = 20
bingLimit int = 200
)
func BingQuery(domain, sub string, l *log.Logger) []string {
var unique []string
if domain != sub {
return unique
}
re := utils.SubdomainRegex(domain)
num := bingLimit / bingQuantity
for i := 0; i < num; i++ {
u := bingURLByPageNum(domain, i)
page, err := utils.GetWebPage(u, nil)
if err != nil {
l.Printf("Bing error: %s: %v", u, err)
break
}
for _, sd := range re.FindAllString(page, -1) {
if u := utils.NewUniqueElements(unique, sd); len(u) > 0 {
unique = append(unique, u...)
}
}
time.Sleep(1 * time.Second)
}
return unique
}
func bingURLByPageNum(domain string, page int) string {
count := strconv.Itoa(bingQuantity)
first := strconv.Itoa((page * bingQuantity) + 1)
u, _ := url.Parse("http://www.bing.com/search")
u.RawQuery = url.Values{"q": {"domain:" + domain},
"count": {count}, "first": {first}, "FORM": {"PORE"}}.Encode()
return u.String()
}