-
Notifications
You must be signed in to change notification settings - Fork 6
/
list_management.go
97 lines (88 loc) · 2.46 KB
/
list_management.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
package prox5
import (
"bufio"
"errors"
"io"
"os"
"strings"
)
// LoadProxyTXT loads proxies from a given seed file and feeds them to the mapBuilder to be later queued automatically for validation.
// Expects one of the following formats for each line:
// - 127.0.0.1:1080
// - 127.0.0.1:1080:user:pass
// - yeet.com:1080
// - yeet.com:1080:user:pass
// - [fe80::2ef0:5dff:fe7f:c299]:1080
// - [fe80::2ef0:5dff:fe7f:c299]:1080:user:pass
func (p5 *ProxyEngine) LoadProxyTXT(seedFile string) (count int) {
f, err := os.Open(seedFile)
if err != nil {
p5.dbgPrint(simpleString(err.Error()))
return 0
}
defer func() {
if err := f.Close(); err != nil {
p5.dbgPrint(simpleString(err.Error()))
}
}()
bs, err := io.ReadAll(f)
if err != nil {
p5.dbgPrint(simpleString(err.Error()))
return 0
}
sockstr := string(bs)
return p5.LoadMultiLineString(sockstr)
}
// LoadSingleProxy loads a SOCKS proxy into our map.
// Expects one of the following formats:
// - 127.0.0.1:1080
// - 127.0.0.1:1080:user:pass
// - yeet.com:1080
// - yeet.com:1080:user:pass
// - [fe80::2ef0:5dff:fe7f:c299]:1080
// - [fe80::2ef0:5dff:fe7f:c299]:1080:user:pass
func (p5 *ProxyEngine) LoadSingleProxy(sock string) bool {
var ok bool
if sock, ok = filter(sock); !ok {
p5.dbgPrint(simpleString("invalid proxy format"))
return false
}
if err := p5.loadSingleProxy(sock); err != nil {
p5.dbgPrint(simpleString(err.Error()))
return false
}
// p5.dbgPrint(simpleString("loaded proxy " + sock))
return true
}
func (p5 *ProxyEngine) loadSingleProxy(sock string) error {
p, ok := p5.proxyMap.add(sock)
if !ok {
return errors.New("proxy already exists")
}
p5.Pending.add(p)
return nil
}
// LoadMultiLineString loads a multiine string object with proxy per line.
// Expects one of the following formats for each line:
// - 127.0.0.1:1080
// - 127.0.0.1:1080:user:pass
// - yeet.com:1080
// - yeet.com:1080:user:pass
// - [fe80::2ef0:5dff:fe7f:c299]:1080
// - [fe80::2ef0:5dff:fe7f:c299]:1080:user:pass
func (p5 *ProxyEngine) LoadMultiLineString(socks string) int {
var count int
scan := bufio.NewScanner(strings.NewReader(socks))
for scan.Scan() {
if err := p5.loadSingleProxy(scan.Text()); err != nil {
continue
}
count++
}
return count
}
// ClearSOCKSList clears the map of proxies that we have on record.
// Other operations (proxies that are still in buffered channels) will continue.
func (p5 *ProxyEngine) ClearSOCKSList() {
p5.proxyMap.clear()
}