-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathhaktldextract.go
53 lines (45 loc) · 1.03 KB
/
haktldextract.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
package main
import (
"bufio"
"flag"
"fmt"
"os"
"sync"
"github.com/hakluke/tldextract"
)
func main() {
concurrencyPtr := flag.Int("t", 8, "Number of threads to utilise. Default is 8.")
subdomainsPtr := flag.Bool("s", false, "dump subdomains instead of base domains")
flag.Parse()
cache := "/tmp/tld.cache"
extract, err := tldextract.New(cache, false)
if err != nil {
fmt.Println(err)
}
numWorkers := *concurrencyPtr
work := make(chan string)
go func() {
s := bufio.NewScanner(os.Stdin)
for s.Scan() {
work <- s.Text()
}
close(work)
}()
wg := &sync.WaitGroup{}
for i := 0; i < numWorkers; i++ {
wg.Add(1)
go doWork(work, wg, *subdomainsPtr, extract)
}
wg.Wait()
}
func doWork(work chan string, wg *sync.WaitGroup, subdomainsPtr bool, extract *tldextract.TLDExtract) {
for url := range work {
result := extract.Extract(url)
if subdomainsPtr && len(result.Sub) > 0 {
fmt.Println(result.Sub + "." + result.Root + "." + result.Tld)
} else {
fmt.Println(result.Root + "." + result.Tld)
}
}
wg.Done()
}