-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
159 lines (133 loc) · 3.91 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package main
import (
"balooChecker/proxy"
"bufio"
"fmt"
"os"
"strconv"
"sync"
"sync/atomic"
"time"
)
var (
sem chan struct{}
checking int32
caughtUp bool
mutex sync.Mutex
numProxies int
definedTimout time.Duration
definedOutput string
)
// Usage ./main [timeout] [output] [threads]
func main() {
sArgs := os.Args
if len(sArgs) < 4 {
fmt.Println("[ Usage ]: ./main [proxy timeout] [output file] [max threads]")
os.Exit(0)
}
go stats()
tTimeout, timeoutErr := strconv.Atoi(sArgs[1])
if timeoutErr != nil {
fmt.Println("[ Error ]: " + timeoutErr.Error())
os.Exit(0)
}
definedTimout = time.Duration(tTimeout) * time.Second
definedOutput = os.Args[2]
tMaxThreads, threadsErr := strconv.Atoi(sArgs[3])
if threadsErr != nil {
fmt.Println("[ Error ]: " + threadsErr.Error())
os.Exit(0)
}
sem = make(chan struct{}, tMaxThreads)
writeToFile(definedOutput+".txt", "[ Output ]: "+time.Now().Format("15:04:05"))
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
caughtUp = false
proxyAddr := scanner.Text()
sem <- struct{}{} // Wait for an open spot
go func(addr string) {
atomic.AddInt32(&checking, 1)
checkProxy(addr, definedTimout)
<-sem // Signal we're done
atomic.AddInt32(&checking, -1)
}(proxyAddr)
}
caughtUp = true
if err := scanner.Err(); err != nil {
fmt.Fprintln(os.Stderr, "Error reading input:", err)
}
time.Sleep(1 * time.Second)
for checking != 0 {
time.Sleep(1 * time.Second)
}
fmt.Println("[ Found " + fmt.Sprint(numProxies) + " Proxies ]!")
displayStats()
}
func stats() {
for {
displayStats()
time.Sleep(1 * time.Minute)
}
}
func displayStats() {
fmt.Println("[ Proxies Found ]: " + fmt.Sprint(numProxies) + " [ HTTP ]: " + fmt.Sprint(proxy.HTTP_FOUND) + " [ HTTPS ]: " + fmt.Sprint(proxy.HTTPS_FOUND) + " [ SOCKS4 ]: " + fmt.Sprint(proxy.SOCKS4_FOUND) + " [ SOCKS5 ]: " + fmt.Sprint(proxy.SOCKS5_FOUND) + " [ Fake ]: " + fmt.Sprint(proxy.FAKE_FOUND) + " [ Checking ]: " + fmt.Sprint(checking) + " [ Caught Up ]: " + fmt.Sprint(caughtUp))
}
func checkProxy(proxyAddr string, proxyTimeout time.Duration) {
respHTTP, errHTTP := proxy.ConnectHTTP(proxyAddr, proxyTimeout)
if errHTTP == nil {
if proxy.ValidateResponse(respHTTP) {
fmt.Println("[ Found ]: " + proxyAddr + " ( HTTP )")
addProxyToList(proxyAddr, proxy.PROXY_HTTP)
}
}
respSOCKS5, errSOCKS5 := proxy.ConnectSOCKS5(proxyAddr, proxyTimeout)
if errSOCKS5 == nil {
if proxy.ValidateResponse(respSOCKS5) {
fmt.Println("[ Found ]: " + proxyAddr + " ( SOCKS5 )")
addProxyToList(proxyAddr, proxy.PROXY_SOCKS5)
}
}
respSOCKS4, errSOCKS4 := proxy.ConnectSOCKS4(proxyAddr, proxyTimeout)
if errSOCKS4 == nil {
if proxy.ValidateResponse(respSOCKS4) {
fmt.Println("[ Found ]: " + proxyAddr + " ( SOCKS4 )")
addProxyToList(proxyAddr, proxy.PROXY_SOCKS4)
}
}
respHTTPS, errHTTPS := proxy.ConnectHTTPS(proxyAddr, proxyTimeout)
if errHTTPS == nil {
if proxy.ValidateResponse(respHTTPS) {
fmt.Println("[ Found ]: " + proxyAddr + " ( HTTPS )")
addProxyToList(proxyAddr, proxy.PROXY_HTTPS)
}
}
}
func addProxyToList(proxyAddr string, proxyType string) {
switch proxyType {
case proxy.PROXY_HTTP:
atomic.AddInt32(&proxy.HTTP_FOUND, 1)
case proxy.PROXY_HTTPS:
atomic.AddInt32(&proxy.HTTPS_FOUND, 1)
case proxy.PROXY_SOCKS4:
atomic.AddInt32(&proxy.SOCKS4_FOUND, 1)
case proxy.PROXY_SOCKS5:
atomic.AddInt32(&proxy.SOCKS5_FOUND, 1)
}
// Ensure only 1 access at a time
mutex.Lock()
numProxies++
writeToFile(definedOutput+".txt", proxyAddr)
writeToFile(definedOutput+"_"+proxyType+".txt", proxyAddr)
mutex.Unlock()
}
func writeToFile(fName string, str string) {
logger, logErr := os.OpenFile(fName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
if logErr != nil {
fmt.Println("[ Error ]: " + logErr.Error())
}
_, err := logger.WriteString(str + "\n")
if err != nil {
fmt.Println("[ Error ]: " + err.Error())
}
defer logger.Close()
}