forked from txthinking/brook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.go
145 lines (129 loc) · 5.1 KB
/
run.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
package brook
import (
"github.com/txthinking/brook/sysproxy"
)
// RunServer used to make a new Server and start to listen
func RunServer(address, password string, tcpTimeout, tcpDeadline, udpDeadline int) error {
s, err := NewServer(address, password, tcpTimeout, tcpDeadline, udpDeadline)
if err != nil {
return err
}
return s.ListenAndServe()
}
// RunClient used to make a new Client and start a socks5 proxy to listen
func RunClient(address, ip, server, password string, tcpTimeout, tcpDeadline, udpDeadline, udpSessionTime int) error {
c, err := NewClient(address, ip, server, password, tcpTimeout, tcpDeadline, udpDeadline, udpSessionTime)
if err != nil {
return err
}
return c.ListenAndServe()
}
// RunClientAsHTTP used to make a new Client and start a http proxy to listen
func RunClientAsHTTP(address, ip, server, password string, tcpTimeout, tcpDeadline, udpDeadline, udpSessionTime int) error {
c, err := NewClient(address, ip, server, password, tcpTimeout, tcpDeadline, udpDeadline, udpSessionTime)
if err != nil {
return err
}
return c.ListenAndServeHTTP()
}
// RunTunnel used to start a tunnel
func RunTunnel(address, to, server, password string, tcpTimeout, tcpDeadline, udpDeadline int) error {
c, err := NewTunnel(address, to, server, password, tcpTimeout, tcpDeadline, udpDeadline)
if err != nil {
return err
}
return c.ListenAndServe()
}
// RunStreamServer used to make a new StreamServer and start to listen
func RunStreamServer(address, password string, tcpTimeout, tcpDeadline, udpDeadline int) error {
s, err := NewStreamServer(address, password, tcpTimeout, tcpDeadline, udpDeadline)
if err != nil {
return err
}
return s.ListenAndServe()
}
// RunStreamClient used to make a new StreamClient and start a socks5 proxy to listen
func RunStreamClient(address, ip, server, password string, tcpTimeout, tcpDeadline, udpDeadline, udpSessionTime int) error {
c, err := NewStreamClient(address, ip, server, password, tcpTimeout, tcpDeadline, udpDeadline, udpSessionTime)
if err != nil {
return err
}
return c.ListenAndServe()
}
// RunClientAsHTTP used to make a new StreamClient and start a http proxy to listen
func RunStreamClientAsHTTP(address, ip, server, password string, tcpTimeout, tcpDeadline, udpDeadline, udpSessionTime int) error {
c, err := NewStreamClient(address, ip, server, password, tcpTimeout, tcpDeadline, udpDeadline, udpSessionTime)
if err != nil {
return err
}
return c.ListenAndServeHTTP()
}
// RunSSServer used to make a new Server and start to listen
func RunSSServer(address, password string, tcpTimeout, tcpDeadline, udpDeadline int) error {
s, err := NewSSServer(address, password, tcpTimeout, tcpDeadline, udpDeadline)
if err != nil {
return err
}
return s.ListenAndServe()
}
// RunSSClient used to make a new Client and start a socks5 proxy to listen
func RunSSClient(address, ip, server, password string, tcpTimeout, tcpDeadline, udpDeadline, udpSessionTime int) error {
c, err := NewSSClient(address, ip, server, password, tcpTimeout, tcpDeadline, udpDeadline, udpSessionTime)
if err != nil {
return err
}
return c.ListenAndServe()
}
// RunSSClientAsHTTP used to make a new Client and start a http proxy to listen
func RunSSClientAsHTTP(address, ip, server, password string, tcpTimeout, tcpDeadline, udpDeadline, udpSessionTime int) error {
c, err := NewSSClient(address, ip, server, password, tcpTimeout, tcpDeadline, udpDeadline, udpSessionTime)
if err != nil {
return err
}
return c.ListenAndServeHTTP()
}
// RunRelay used to make a new Relay and start to listen
func RunRelay(address, remote string, tcpTimeout, tcpDeadline, udpDeadline int) error {
r, err := NewRelay(address, remote, tcpTimeout, tcpDeadline, udpDeadline)
if err != nil {
return err
}
return r.ListenAndServe()
}
// RunSocks5Server used to make a new Socks5Server and start a raw socks5 proxy to listen
func RunSocks5Server(address, ip, username, password string, tcpTimeout, tcpDeadline, udpDeadline, udpSessionTime int) error {
s, err := NewSocks5Server(address, ip, username, password, tcpTimeout, tcpDeadline, udpDeadline, udpSessionTime)
if err != nil {
return err
}
return s.ListenAndServe()
}
// RunSocks5ToHTTP used to make a new Socks5ToHTTP and start a http proxy to listen
func RunSocks5ToHTTP(address, socks5 string, timeout, deadline int) error {
s, err := NewSocks5ToHTTP(address, socks5, timeout, deadline)
if err != nil {
return err
}
return s.ListenAndServe()
}
// RunSystemProxy used to set/remove system proxy
func RunSystemProxy(remove bool, pac string) error {
if remove {
if err := sysproxy.TurnOffSystemProxy(); err != nil {
return err
}
return nil
}
if err := sysproxy.TurnOnSystemProxy(pac); err != nil {
return err
}
return nil
}
// RunVPN used to make a new VPN and start
func RunVPN(address, server, password string, tcpTimeout, tcpDeadline, udpDeadline, udpSessionTime int, tunDevice, tunIP, tunGateway, tunMask, defaultGateway string) error {
v, err := NewVPN(address, server, password, tcpTimeout, tcpDeadline, udpDeadline, udpSessionTime, tunDevice, tunIP, tunGateway, tunMask, defaultGateway)
if err != nil {
return err
}
return v.ListenAndServe()
}