-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
116 lines (99 loc) · 2.79 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
package main
import (
"flag"
"fmt"
"log"
"net"
"os"
"runtime"
"strings"
"github.com/mullvad/apisocks5/internal/proxy"
"github.com/mullvad/apisocks5/internal/proxy/typ"
)
var appVersion string
func main() {
listenAddr := flag.String("listen-addr", "127.0.0.1:1080", "listen address and port")
sourceDomains := flag.String("source-domains", "frakta.eu", "source domains")
verbose := flag.Bool("verbose", false, "verbose output")
version := flag.Bool("version", false, "display version and exit")
usePlainProxies := flag.Bool("use-plain-proxies", true, "use plain proxies")
useXORProxies := flag.Bool("use-xor-proxies", true, "use xor proxies")
useXORV2Proxies := flag.Bool("use-xor-v2-proxies", true, "use xor v2 proxies")
flag.Parse()
if *version {
fmt.Fprintf(
os.Stdout,
"%s version %s %s/%s\n",
os.Args[0], appVersion, runtime.GOOS, runtime.GOARCH,
)
os.Exit(0)
}
if !*usePlainProxies && !*useXORProxies && !*useXORV2Proxies {
log.Fatalf("neither -use-plain-proxy, -use-xor-proxy or -use-xor-v2-proxies-was set")
}
if *sourceDomains == "" {
log.Fatalf("no -source-domains specified")
}
var domains []string
for _, d := range strings.Split(*sourceDomains, ",") {
domains = append(domains, strings.TrimSpace(d))
}
domains = uniqueShuffle(domains)
listener, err := net.Listen("tcp4", *listenAddr)
if err != nil {
log.Fatalf("Unable to bind port, %v\n", err)
}
log.Printf("Listening on %s\n", *listenAddr)
for {
conn, err := listener.Accept()
if err != nil {
log.Printf("Failed to accept connection, %v\n", err)
continue
}
proxies := proxy.Query(domains, *verbose)
if len(proxies) == 0 {
log.Printf("No proxies returned from the source domains\n")
continue
}
var plainProxies []proxy.Proxy
var xorProxies []proxy.Proxy
var xorV2Proxies []proxy.Proxy
for _, p := range proxies {
if *usePlainProxies && p.Type() == typ.Plain {
plainProxies = append(plainProxies, p)
} else if *useXORProxies && p.Type() == typ.XOR {
xorProxies = append(xorProxies, p)
} else if *useXORV2Proxies && p.Type() == typ.XORV2 {
xorV2Proxies = append(xorV2Proxies, p)
}
}
var allProxies []proxy.Proxy
if *useXORV2Proxies {
allProxies = append(allProxies, xorV2Proxies...)
}
if *useXORProxies {
allProxies = append(allProxies, xorProxies...)
}
if *usePlainProxies {
allProxies = append(allProxies, plainProxies...)
}
if len(allProxies) == 0 {
log.Printf("No proxies returned from the source domains match your preferred selection\n")
continue
}
go handleSOCKS5Conn(conn, allProxies, *verbose)
}
}
func uniqueShuffle(input []string) []string {
tmp := make(map[string]bool)
for _, i := range input {
tmp[i] = true
}
out := make([]string, len(tmp))
i := 0
for t := range tmp {
out[i] = t
i++
}
return out
}