-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathk2.go
99 lines (82 loc) · 2.27 KB
/
k2.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
k2: Reverse whois lookup
by github.com/harleo — MIT License
*/
package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"strings"
"github.com/PuerkitoBio/goquery"
)
type registrarInfo struct {
name string
creation_date string
registrar string
}
var whoIs []registrarInfo
func writeLines(lines []string, path string) error {
file, err := os.Create(path)
if err != nil {
log.Fatalf("[!] Couldn't create %s file: %s\n", path, err.Error())
}
defer file.Close()
w := bufio.NewWriter(file)
for _, line := range lines {
fmt.Fprintln(w, line)
}
return w.Flush()
}
func main() {
namePtr := flag.String("n", "", "Registrant name, email or domain name of the target (Required)")
printPtr := flag.Bool("p", false, "Print results")
outputPtr := flag.String("o", "domains.txt", "Output file to write results to")
flag.Parse()
if *namePtr == "" {
flag.PrintDefaults()
os.Exit(0)
}
fmt.Println("[:] Sending query...")
doc, err := goquery.NewDocument(fmt.Sprintf("https://viewdns.info/reversewhois/?q=%s", *namePtr))
if err != nil {
log.Fatalf("[!] Couldn't send query request: %s\n", err.Error())
}
// API uses Cloudflare, most likely all cloud IPs require captcha verification whereas residential IPs are able to pass
doc.Find("html").Each(func(_ int, body *goquery.Selection) {
if strings.Contains(body.Text(), "Cloudflare Ray ID") {
fmt.Println("[!] Query was blocked by Cloudflare captcha, try from a different IP.")
os.Exit(0)
}
})
doc.Find("html body font table#null tbody tr td font table tbody tr").Each(func(_ int, tr *goquery.Selection) {
e := registrarInfo{}
tr.Find("td").Each(func(ix int, td *goquery.Selection) {
switch ix {
case 0:
e.name = td.Text()
case 1:
e.creation_date = td.Text()
case 2:
e.registrar = td.Text()
}
})
whoIs = append(whoIs, e)
})
if len(whoIs) > 0 {
var domainNames []string
for _, domain := range whoIs[1:] {
domainNames = append(domainNames, domain.name)
if *printPtr {
fmt.Printf("%s | %s | %s\n", domain.name, domain.creation_date, domain.registrar)
}
}
fmt.Printf("[:] Writing %d domain(s) to file %s...\n", len(domainNames), *outputPtr)
writeLines(domainNames, *outputPtr)
} else {
fmt.Println("[!] No domains found")
}
fmt.Println("[:] Done.")
}