-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvoter.go
164 lines (147 loc) · 4.32 KB
/
voter.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package main
import (
"time"
"net"
"net/url"
"net/http"
"io/ioutil"
"math/rand"
"sync"
"runtime"
"log"
)
var timeout = time.Duration(3 * time.Second)
var wg = new(sync.WaitGroup)
var addProxy = make(chan string)
var proxyList = make(map[string] string)
var quit = make(chan bool)
var runningClicker = false
var useragents = [...]string{
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)",
"Googlebot/2.1 (http://www.googlebot.com/bot.html)",
"Opera/9.20 (Windows NT 6.0; U; en)",
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.1) Gecko/20061205 Iceweasel/2.0.0.1 (Debian-2.0.0.1+dfsg-2)",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; FDM; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 1.1.4322)",
"Opera/10.00 (X11; Linux i686; U; en) Presto/2.2.0",
"Mozilla/5.0 (Windows; U; Windows NT 6.0; he-IL) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16",
"Mozilla/5.0 (compatible; Yahoo! Slurp/3.0; http://help.yahoo.com/help/us/ysearch/slurp)",
"Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Firefox/3.6.13",
"Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 5.1; Trident/5.0)",
"Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
"Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)",
"Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)",
"Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)",
"Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8) Gecko/20100804 Gentoo Firefox/3.6.8",
"Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.7) Gecko/20100809 Fedora/3.6.7-1.fc14 Firefox/3.6.7",
"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
"Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)",
"YahooSeeker/1.2 (compatible; Mozilla 4.0; MSIE 5.5; yahooseeker at yahoo-inc dot com ; http://help.yahoo.com/help/us/shop/merchant/)",
"Mozilla/5.0 (Linux x86_64; rv:33.0) Firefox/33.0",
}
func dialTimeout() func(net, addr string) (c net.Conn, err error) {
return func(netw, addr string) (net.Conn, error) {
conn, err := net.DialTimeout(netw, addr, timeout)
if err != nil {
return nil, err
}
conn.SetDeadline(time.Now().Add(timeout))
tcp_conn := conn.(*net.TCPConn)
tcp_conn.SetLinger(0)
return tcp_conn, err
}
}
func worker(proxyChan chan string, wg *sync.WaitGroup) {
defer wg.Done()
for proxy := range proxyChan {
if visit(proxy) {
addProxy <- proxy
}
}
}
func voter() {
if runningClicker {
return
}
runningClicker = true
proxyCh := make(chan string)
handleNewProxys()
Message("Add 50 worker", false)
for i := 0; i < 50; i++ {
wg.Add(1)
go worker(proxyCh, wg)
}
Message("Read proxy.txt file", false)
lines, err := readLines("proxy.txt")
if err != nil {
log.Println("readLines: %s", err)
}
Message("Start click process", false)
for _, line := range lines {
select {
case <- quit:
runningClicker = false
Message("Voter stopped", false)
return
default:
proxyCh <- line
}
}
runtime.GC()
Message("Use only good proxies", false)
for {
for _, line := range proxyList {
select {
case <- quit:
runningClicker = false
Message("Voter stopped", false)
return
default:
proxyCh <- line
}
}
runtime.GC()
}
close(proxyCh)
wg.Wait()
}
func visit(proxy string) bool {
if proxy == "" {
return false
}
Message(proxy + "|use", true)
proxyUrl, err := url.Parse("http://" + proxy)
transport := &http.Transport{
Dial: dialTimeout(),
Proxy: http.ProxyURL(proxyUrl),
DisableKeepAlives: true,
}
transport.CloseIdleConnections()
client := &http.Client{
Transport: transport,
}
req, err := http.NewRequest("GET", urlTarget, nil)
if err != nil {
return false
}
req.Header.Set("User-Agent", useragents[rand.Intn(len(useragents))])
resp, err := client.Do(req)
if err != nil {
return false
} else {
contents, err := ioutil.ReadAll(resp.Body)
if err != nil {
resp.Body.Close()
return false
} else {
if string(contents) != "" {
Message(proxy + "|work", true)
resp.Body.Close()
return true
}
resp.Body.Close()
return false
}
}
return false
}