forked from pingc0y/go_proxy_pool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (63 loc) · 1.5 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
package main
import (
"fmt"
"log"
"os"
"time"
)
func init() {
// 设置全局日志格式和输出
log.SetFlags(log.LstdFlags | log.Lshortfile)
log.SetOutput(os.Stdout)
}
func main() {
fmt.Println(" ___ ___ _ " +
"\n ___ ___ | . " + "\\ _ _ ___ __ _ _ | . \\ ___ ___ | |" +
"\n/ . |/ . \\| _/| '_>/ . \\\\ \\/| | || _// . \\/ . \\| |" +
"\n\\_. |\\___/|_| |_| \\___//\\_\\`_. ||_| \\___/\\___/|_|" +
"\n<___' <___' ")
initSqlite()
InitData()
//开启隧道代理
go httpRunTunnelProxyServer()
go socket5RunTunnelProxyServer()
//启动webAPi
Run()
}
// 初始化
func InitData() {
//获取配置文件
GetConfigData()
//设置线程数量
ch1 = make(chan int, conf.Config.ThreadNum)
ch2 = make(chan int, conf.Config.ThreadNum)
//是否需要抓代理
if getWorkingCount("all") < conf.Config.ProxyNum {
//抓取代理
spiderRun()
}
//定时判断是否需要获取代理iP
go func() {
// 每 60 秒钟时执行一次
ticker := time.NewTicker(60 * time.Second)
for range ticker.C {
if getWorkingCount("all") < conf.Config.ProxyNum {
if !run {
log.Printf("代理数量不足 %d\n", conf.Config.ProxyNum)
//抓取代理
spiderRun()
}
}
}
}()
// 验证代理存活情况
go func() {
verifyTime := time.Duration(conf.Config.VerifyTime)
ticker := time.NewTicker(verifyTime * time.Second)
for range ticker.C {
if !verifyIS {
VerifyProxy()
}
}
}()
}