-
Notifications
You must be signed in to change notification settings - Fork 18
/
fanout.go
121 lines (95 loc) · 2.24 KB
/
fanout.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//https://github.com/sunfmin/domaincheck/blob/master/main.go
package main
import (
"flag"
"fmt"
"github.com/mozillazg/go-pinyin"
"github.com/sunfmin/fanout"
"io/ioutil"
"os"
"os/exec"
"strings"
)
var file = flag.String("file", "", "每行一个词语的列表文本文件")
var workers = flag.Int("workers", 60, "并发数")
func main() {
flag.Parse()
fmt.Println(*file)
f, err := os.Open(*file)
if err != nil {
fmt.Println(err)
return
}
fbytes, err := ioutil.ReadAll(f)
if err != nil {
fmt.Println(err)
return
}
words := strings.Split(string(fbytes), "\n")
inputs := []interface{}{}
for _, word := range words {
inputs = append(inputs, word)
}
a := pinyin.NewArgs()
results, err2 := fanout.ParallelRun(*workers, func(input interface{}) (interface{}, error) {
word := input.(string)
if strings.TrimSpace(word) == "" {
return nil, nil
}
pya := pinyin.Pinyin(word, a)
py := ""
for _, pye := range pya {
py = py + pye[0]
}
pydowncase := strings.ToLower(py)
domain := pydowncase + ".com"
outr, err := domainAvailable(word, domain)
if err != nil {
fmt.Println("Error: ", err)
return nil, nil
}
if outr.available {
fmt.Printf("[Ohh Yeah] %s %s\n", outr.word, outr.domain)
}
fmt.Printf("\t\t\t %s %s %s\n", outr.word, outr.domain, outr.summary)
return outr, nil
}, inputs)
fmt.Println("Finished ", len(results), ", Error:", err2)
}
type checkResult struct {
word string
domain string
available bool
summary string
}
func domainAvailable(word string, domain string) (ch checkResult, err error) {
var summary string
var output []byte
ch.word = word
ch.domain = domain
cmd := exec.Command("whois", domain)
output, err = cmd.Output()
if err != nil {
fmt.Println(err)
return
}
outputstring := string(output)
if strings.Contains(outputstring, "No match for \"") {
ch.available = true
return
}
summary = firstLineOf(outputstring, "Registrant Name") + " => "
summary = summary + firstLineOf(outputstring, "Expiration Date")
ch.summary = summary
return
}
func firstLineOf(content string, keyword string) (line string) {
lines := strings.Split(content, "\n")
for _, l := range lines {
if strings.Contains(l, keyword) {
line = l
return
}
}
return
}