Skip to content

Commit eaabd69

Browse files
committed
Tweaks subdomains tool
1 parent d431b87 commit eaabd69

File tree

3 files changed

+1928
-21
lines changed

3 files changed

+1928
-21
lines changed

subs/domains

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sbtuk.net
2+
tomnomnom.uk
3+
tomnomnom.com

subs/main.go

+18-21
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func main() {
2020
subdomainsFile := flag.Arg(1)
2121

2222
if domainsFile == "" {
23-
domainsFile = "domains"
23+
domainsFile = "apexes"
2424
}
2525

2626
if subdomainsFile == "" {
@@ -41,9 +41,8 @@ func main() {
4141
ss := bufio.NewScanner(s)
4242

4343
type domain struct {
44-
name string
45-
wildcards []string
46-
subs chan string
44+
name string
45+
subs chan string
4746
}
4847

4948
// make a slice of all the domains and spin up a worker for each one
@@ -53,22 +52,28 @@ func main() {
5352
for ds.Scan() {
5453
name := ds.Text()
5554

56-
wildcards, _ := net.LookupHost(fmt.Sprintf("%s.%s", wildcardCheck, name))
55+
_, err := net.LookupHost(fmt.Sprintf("%s.%s", wildcardCheck, name))
56+
if err == nil {
57+
// There's a wildcard, don't bother
58+
continue
59+
}
5760

58-
subs := make(chan string)
59-
d := domain{name, wildcards, subs}
61+
subs := make(chan string, 128)
62+
d := domain{name, subs}
6063
domains = append(domains, d)
6164

62-
wg.Add(1)
63-
go func() {
65+
worker := func() {
6466
for sub := range d.subs {
6567
candidate := fmt.Sprintf("%s.%s", sub, d.name)
66-
if subdomainExists(candidate, d.wildcards) {
68+
if subdomainExists(candidate) {
6769
fmt.Println(candidate)
6870
}
6971
}
7072
wg.Done()
71-
}()
73+
}
74+
wg.Add(2)
75+
go worker()
76+
go worker()
7277
}
7378

7479
// check for errors reading the list of domains
@@ -97,19 +102,11 @@ func main() {
97102
wg.Wait()
98103
}
99104

100-
func subdomainExists(subdomain string, wildcards []string) bool {
101-
addrs, err := net.LookupHost(subdomain)
105+
func subdomainExists(subdomain string) bool {
106+
_, err := net.LookupHost(subdomain)
102107
if err != nil {
103108
return false
104109
}
105110

106-
for _, addr := range addrs {
107-
for _, wildcard := range wildcards {
108-
if addr == wildcard {
109-
return false
110-
}
111-
}
112-
}
113-
114111
return true
115112
}

0 commit comments

Comments
 (0)