-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
executable file
·144 lines (130 loc) · 3.07 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"bufio"
"context"
"flag"
"fmt"
"io/ioutil"
"os"
"regexp"
"strings"
"sync"
"github.com/chromedp/chromedp/device"
"github.com/chromedp/chromedp"
"github.com/panjf2000/ants"
)
var domain_list = make(chan string, 20)
var wg sync.WaitGroup
func readfile(filename string) {
file, err := os.Open(filename)
defer file.Close()
defer close(domain_list)
if err == nil {
r := bufio.NewReader(file)
for {
domain_b, _, err := r.ReadLine()
domain := strings.Replace(string(domain_b), " ", "", -1)
if len(string(domain)) != 0 && err == nil {
domain_list <- string(domain)
} else {
break
}
}
} else {
fmt.Println("readfile_err: ", err)
}
}
func getscreen(domain string, savepath string) (bool, string) {
ctx, cancel := chromedp.NewContext(context.Background())
defer cancel()
if len(domain)==0{
return false,""
}
match, _ := regexp.MatchString("^(http|https)://", domain)
if !match {
domain = "http://" + domain
}
var b2 []byte
if err := chromedp.Run(ctx,
chromedp.Emulate(device.Reset),
chromedp.EmulateViewport(1920, 920),
chromedp.Navigate(domain),
chromedp.CaptureScreenshot(&b2),
); err != nil {
}
if len(b2)==0{
return false,""
}
// 根据domain设置文件名
domain_res := strings.TrimLeft(domain, "http://")
domain_res = strings.TrimLeft(domain_res, "https://")
re3, _ := regexp.Compile("[^A-Za-z0-9\u4e00-\u9fa5]");
output_filename := re3.ReplaceAllString(domain_res, "_");
// 如果文件夹不存在则创建
_, err := os.Stat(savepath)
if err != nil {
if os.IsNotExist(err) {
os.Mkdir(savepath, 0777)
}
}
_, err = os.Stat(savepath+"/img")
if err != nil {
if os.IsNotExist(err) {
os.Mkdir(savepath+"/img", 0777)
}
}
savepath = strings.TrimRight(savepath, "/")
savepath = strings.TrimRight(savepath, "\\")
if err := ioutil.WriteFile(savepath+"/img/"+output_filename+".png", b2, 0777); err != nil {
fmt.Println("2", err)
}
return true, output_filename
}
func main() {
var domain_file string
var output_path string
flag.StringVar(&domain_file, "f", "domain.txt", "目标存放文件")
flag.StringVar(&output_path, "o", "./output", "输出的文件夹")
flag.Parse()
p, _ := ants.NewPool(1000)
os.Mkdir(output_path, 0777)
md_file, err := os.OpenFile(output_path+"/index.md", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777) //写入的md文件
if err != nil {
if os.IsNotExist(err) {
os.Mkdir(output_path, 0777)
}
}
p.Submit(func() {
readfile(domain_file)
})
for {
domain, isclose := <-domain_list
if len(domain) == 0{
if !isclose && len(domain_list) <= 0 {
break
}else{
continue
}
}
wg.Add(1)
_ = p.Submit(func() {
defer wg.Done()
isok, filename := getscreen(domain, output_path)
if isok {
fmt.Println("[+] "+domain)
md_link := "# [" + domain + "](" + domain + ")"
md_pic := "![" + filename + ".png](img/" + filename + ".png)"
md_file.WriteString(md_link + "\n\n\n" + md_pic + "\n")
}else{
if len(domain)!=0{
fmt.Println("[-] "+domain)
}
}
})
if !isclose && len(domain_list) <= 0 {
break
}
}
wg.Wait()
return
}