Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
130 lines (114 loc) · 2.76 KB
/
Copy pathmain.go
File metadata and controls
130 lines (114 loc) · 2.76 KB
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
package main
import (
"bufio"
"flag"
"fmt"
"github.com/cheggaaa/pb/v3"
"io"
"log"
"net"
"os"
"proxyChecker/checker"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
)
var outputFile string
func getList(filename string) ([]net.TCPAddr, error) {
file, err := os.Open(filename)
if err != nil {
return nil, err
}
defer file.Close()
var tcpAddrs []net.TCPAddr
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
temp := strings.Split(strings.TrimSpace(line), ":")
if len(temp) != 2 {
continue
}
ip := temp[0]
port, err := strconv.Atoi(temp[1])
if err != nil {
continue
}
addr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", ip, port))
if err != nil {
continue
}
tcpAddrs = append(tcpAddrs, *addr)
}
if err := scanner.Err(); err != nil {
return nil, err
}
return tcpAddrs, nil
}
func main() {
var inputFile string
var maxGoroutines int
var checkSocks4, checkSocks5 bool
var dialTimeout, readTimeout time.Duration
flag.StringVar(&inputFile, "if", "list.txt", "File with list of proxies")
flag.IntVar(&maxGoroutines, "max", 5000, "Maximum number of goroutines")
flag.BoolVar(&checkSocks4, "s4", true, "Check for SOCKS4 proxies")
flag.BoolVar(&checkSocks5, "s5", true, "Check for SOCKS5 proxies")
flag.DurationVar(&dialTimeout, "dt", 5*time.Second, "Dial timeout duration")
flag.DurationVar(&readTimeout, "rt", 10*time.Second, "Read timeout duration")
flag.StringVar(&outputFile, "of", "", "Output file to write results to (defaults to stdout)")
flag.Parse()
ipList, err := getList(inputFile)
if err != nil {
log.Fatal(err)
}
semaphore := make(chan struct{}, maxGoroutines)
var wg sync.WaitGroup
var output io.Writer
var progressBar *pb.ProgressBar
var counter int64
if outputFile != "" {
file, err := os.Create(outputFile)
if err != nil {
log.Fatalf("Failed to create output file: %v", err)
}
defer file.Close()
output = file
// Initialize and start the progress bar
progressBar = pb.StartNew(len(ipList) * (boolToInt(checkSocks4) + boolToInt(checkSocks5)))
} else {
output = os.Stdout
}
for _, ip := range ipList {
wg.Add(1)
go func(ip net.TCPAddr) {
defer wg.Done()
if checkSocks4 {
checker.IsSocks4(ip, semaphore, dialTimeout, readTimeout, output)
updateProgress(progressBar, &counter)
}
if checkSocks5 {
checker.IsSocks5(ip, semaphore, dialTimeout, readTimeout, output)
updateProgress(progressBar, &counter)
}
}(ip)
}
wg.Wait()
if progressBar != nil {
progressBar.Finish()
}
time.Sleep(1 * time.Second)
}
func boolToInt(b bool) int {
if b {
return 1
}
return 0
}
func updateProgress(progressBar *pb.ProgressBar, counter *int64) {
if progressBar != nil {
atomic.AddInt64(counter, 1)
progressBar.SetCurrent(*counter)
}
}