-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
97 lines (81 loc) · 1.68 KB
/
main.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
package main
import (
"bufio"
"encoding/json"
"flag"
"fmt"
"os"
"strings"
"sync"
"github.com/haccer/available"
)
var wordlistFile string
var jsonOutput bool
func init() {
flag.StringVar(&wordlistFile, "w", "", "Wordlist file")
flag.BoolVar(&jsonOutput, "json", false, "Output results in JSON format")
}
type Result struct {
Domain string `json:"domain"`
}
func main() {
flag.Parse()
scanner := bufio.NewScanner(os.Stdin)
uniqueDomains := make(map[string]bool)
var wg sync.WaitGroup
workerCount := 100
jobs := make(chan string, workerCount)
results := []Result{}
for w := 1; w <= workerCount; w++ {
go func() {
for domain := range jobs {
available := available.Domain(domain)
if available {
if jsonOutput {
result := Result{Domain: domain}
results = append(results, result)
} else {
fmt.Println(domain)
}
}
wg.Done()
}
}()
}
if wordlistFile != "" {
file, err := os.Open(wordlistFile)
if err != nil {
fmt.Println("Error opening wordlist file:", err)
return
}
defer file.Close()
fileScanner := bufio.NewScanner(file)
for fileScanner.Scan() {
email := fileScanner.Text()
at := strings.LastIndex(email, "@")
if at >= 0 {
domain := email[at+1:]
uniqueDomains[domain] = true
}
}
} else {
for scanner.Scan() {
email := scanner.Text()
at := strings.LastIndex(email, "@")
if at >= 0 {
domain := email[at+1:]
uniqueDomains[domain] = true
}
}
}
for domain := range uniqueDomains {
wg.Add(1)
jobs <- domain
}
close(jobs)
wg.Wait()
if jsonOutput && len(results) > 0 {
jsonData, _ := json.MarshalIndent(results, "", " ")
fmt.Println(string(jsonData))
}
}