Skip to content

Commit bab614d

Browse files
committed
v20230101
1 parent 54ec07a commit bab614d

File tree

9 files changed

+378
-44
lines changed

9 files changed

+378
-44
lines changed

cli/brook/main.go

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var debugAddress string
5050
func main() {
5151
app := cli.NewApp()
5252
app.Name = "Brook"
53-
app.Version = "20221212"
53+
app.Version = "20230101"
5454
app.Usage = "A cross-platform network tool designed for developers"
5555
app.Authors = []*cli.Author{
5656
{
@@ -221,7 +221,7 @@ func main() {
221221
},
222222
&cli.StringFlag{
223223
Name: "http",
224-
Usage: "Where to listen for HTTP connections",
224+
Usage: "Where to listen for HTTP proxy connections",
225225
},
226226
&cli.IntFlag{
227227
Name: "tcpTimeout",
@@ -443,7 +443,7 @@ func main() {
443443
},
444444
&cli.StringFlag{
445445
Name: "http",
446-
Usage: "Where to listen for HTTP connections",
446+
Usage: "Where to listen for HTTP proxy connections",
447447
},
448448
&cli.IntFlag{
449449
Name: "tcpTimeout",
@@ -712,7 +712,7 @@ func main() {
712712
},
713713
&cli.StringFlag{
714714
Name: "http",
715-
Usage: "Where to listen for HTTP connections",
715+
Usage: "Where to listen for HTTP proxy connections",
716716
},
717717
&cli.IntFlag{
718718
Name: "tcpTimeout",
@@ -1509,7 +1509,7 @@ func main() {
15091509
},
15101510
&cli.StringFlag{
15111511
Name: "http",
1512-
Usage: "Where to listen for HTTP connections",
1512+
Usage: "Where to listen for HTTP proxy connections",
15131513
},
15141514
&cli.IntFlag{
15151515
Name: "tcpTimeout",
@@ -2090,7 +2090,12 @@ func main() {
20902090
var cmd *exec.Cmd
20912091
var err error
20922092
go func() {
2093-
cmd = exec.Command("brook", "connect", "--link", c.String("link"), "--socks5", c.String("socks5"))
2093+
var s string
2094+
s, err = os.Executable()
2095+
if err != nil {
2096+
return
2097+
}
2098+
cmd = exec.Command(s, "connect", "--link", c.String("link"), "--socks5", c.String("socks5"))
20942099
b, _ := cmd.CombinedOutput()
20952100
err = errors.New(string(b))
20962101
}()
@@ -2103,6 +2108,76 @@ func main() {
21032108
return err1
21042109
},
21052110
},
2111+
&cli.Command{
2112+
Name: "echoserver",
2113+
Usage: "Echo server, echo UDP and TCP address of routes",
2114+
BashComplete: func(c *cli.Context) {
2115+
l := c.Command.VisibleFlags()
2116+
for _, v := range l {
2117+
fmt.Println("--" + v.Names()[0])
2118+
}
2119+
},
2120+
Flags: []cli.Flag{
2121+
&cli.StringFlag{
2122+
Name: "listen",
2123+
Aliases: []string{"l"},
2124+
Usage: "Listen address, like: ':7777'",
2125+
},
2126+
},
2127+
Action: func(c *cli.Context) error {
2128+
if c.String("listen") == "" {
2129+
return cli.ShowSubcommandHelp(c)
2130+
}
2131+
s, err := brook.NewEchoServer(c.String("listen"))
2132+
if err != nil {
2133+
return err
2134+
}
2135+
g := runnergroup.New()
2136+
g.Add(&runnergroup.Runner{
2137+
Start: func() error {
2138+
return s.ListenAndServe()
2139+
},
2140+
Stop: func() error {
2141+
return s.Shutdown()
2142+
},
2143+
})
2144+
go func() {
2145+
sigs := make(chan os.Signal, 1)
2146+
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
2147+
<-sigs
2148+
g.Done()
2149+
}()
2150+
return g.Wait()
2151+
},
2152+
},
2153+
&cli.Command{
2154+
Name: "echoclient",
2155+
Usage: "Connect to echoserver, echo UDP and TCP address of routes",
2156+
BashComplete: func(c *cli.Context) {
2157+
l := c.Command.VisibleFlags()
2158+
for _, v := range l {
2159+
fmt.Println("--" + v.Names()[0])
2160+
}
2161+
},
2162+
Flags: []cli.Flag{
2163+
&cli.StringFlag{
2164+
Name: "server",
2165+
Aliases: []string{"s"},
2166+
Usage: "Echo server address, such as 1.2.3.4:7777",
2167+
},
2168+
&cli.IntFlag{
2169+
Name: "times",
2170+
Value: 1,
2171+
Usage: "Times of interactions",
2172+
},
2173+
},
2174+
Action: func(c *cli.Context) error {
2175+
if c.String("server") == "" {
2176+
return cli.ShowSubcommandHelp(c)
2177+
}
2178+
return brook.EchoClient(c.String("server"), c.Int("times"))
2179+
},
2180+
},
21062181
&cli.Command{
21072182
Name: "completion",
21082183
Usage: "Generate shell completions",
@@ -2188,7 +2263,7 @@ complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete brook
21882263
},
21892264
},
21902265
&cli.Command{
2191-
Name: "markdown",
2266+
Name: "mdpage",
21922267
Usage: "Generate markdown page",
21932268
BashComplete: func(c *cli.Context) {
21942269
l := c.Command.VisibleFlags()

docs/example-zh.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ brook dnsserveroverbrook ... --listen 127.0.0.1:53
259259
**无需操作 iptables!**
260260

261261
```
262-
opkg install ca-certificates openssl-util ca-bundle coreutils-nohup iptables-mod-tproxy
262+
opkg update
263+
opkg install ca-certificates openssl-util ca-bundle coreutils-nohup iptables-mod-tproxy iptables-mod-socket
263264
```
264265

265266
```
@@ -310,7 +311,10 @@ brook tproxy --link 'brook://...' --dnsListen :53
310311

311312
### 官网原版 OpenWrt 图形客户端
312313

313-
> **依赖: ca-certificates openssl-util ca-bundle coreutils-nohup iptables-mod-tproxy**
314+
```
315+
opkg update
316+
opkg install ca-certificates openssl-util ca-bundle coreutils-nohup iptables-mod-tproxy iptables-mod-socket
317+
```
314318

315319
**无需操作 iptables!**
316320

docs/example.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ Rule
259259
**No need to manipulate iptables!**
260260

261261
```
262-
opkg install ca-certificates openssl-util ca-bundle coreutils-nohup iptables-mod-tproxy
262+
opkg update
263+
opkg install ca-certificates openssl-util ca-bundle coreutils-nohup iptables iptables-mod-tproxy iptables-mod-socket
263264
```
264265

265266
```
@@ -310,7 +311,10 @@ brook tproxy --link 'brook://...' --dnsListen :53
310311

311312
### GUI for official OpenWrt
312313

313-
> **Dependencies: ca-certificates openssl-util ca-bundle coreutils-nohup iptables-mod-tproxy**
314+
```
315+
opkg update
316+
opkg install ca-certificates openssl-util ca-bundle coreutils-nohup iptables iptables-mod-tproxy iptables-mod-socket
317+
```
314318

315319
**No need to manipulate iptables!**
316320

docs/images/linux.png

4.7 KB
Loading

docs/index.html

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ <h6><a href="https://github.com/txthinking/tun2brook" target="_blank">tun2brook<
175175
<hr />
176176
<div>
177177
<h6>
178-
via pacman <a style="text-decoration: none" href="https://github.com/felixonmars" target="_blank"><i style="font-size: 10px">{{ zh ? '由 felixonmars 维护' : 'maintained by felixonmars' }}</i></a>
178+
via pacman <a style="text-decoration: none" href="https://archlinux.org/packages/community/x86_64/brook/" target="_blank"><i style="font-size: 10px">{{ zh ? '由 felixonmars 维护' : 'maintained by felixonmars' }}</i></a>
179179
</h6>
180180
</div>
181181
<pre><code>pacman -S brook</code></pre>
@@ -217,16 +217,19 @@ <h6>
217217
<div style="font-size: 12px">Windows EXE</div>
218218
</div></a
219219
>
220-
<a href="https://github.com/txthinking/brook/releases" target="_blank"
220+
<div style="display:flex;flex-direction:column;align-items:center;">
221+
<a href="https://github.com/txthinking/brook/releases/latest/download/Brook.bin" target="_blank"
221222
><div style="display: flex; flex-direction: column; align-items: center; padding: 30px">
222-
<img src="./images/openwrt.png" style="width: 50px; height: 50px" />
223-
<div style="font-size: 12px">OpenWrt IPK</div>
223+
<img src="./images/linux.png" style="width: 50px; height: 50px" />
224+
<div style="font-size: 12px">Linux GUI</div>
224225
</div></a
225226
>
226-
<a href="https://chrome.google.com/webstore/detail/hnpgnjkeaobghpjjhaiemlahikgmnghb" target="_blank"
227+
<i data-tooltip="Tested on Ubuntu 22.04. Other systems may need to install dependencies according to the output" style="font-size:9px">deps</i>
228+
</div>
229+
<a href="https://github.com/txthinking/brook/blob/master/docs/example.md#gui-for-official-openwrt" target="_blank"
227230
><div style="display: flex; flex-direction: column; align-items: center; padding: 30px">
228-
<img src="./images/sc.png" style="width: 50px; height: 50px" />
229-
<div style="font-size: 12px">Chrome EXT</div>
231+
<img src="./images/openwrt.png" style="width: 50px; height: 50px" />
232+
<div style="font-size: 12px">OpenWrt IPK</div>
230233
</div></a
231234
>
232235
</div>
@@ -284,9 +287,9 @@ <h6>{{ zh ? '移除某个开机命令' : 'Remove one added command' }}</h6>
284287
<article v-html="p7c"></article>
285288
</div>
286289
</main>
287-
<footer class="container" style="font-size: 14px; color: #919191">
290+
<footer class="container" style="font-size: 14px">
288291
<center>
289-
<p style="font-size: 14px; color: #919191"><a style="font-size: 14px; color: #919191" href="https://github.com/txthinking/brook/tree/master/protocol">Protocol</a></p>
292+
<p style="font-size: 14px"><a style="font-size: 14px" href="https://github.com/txthinking/brook/tree/master/protocol">Undetectable Protocol</a></p>
290293
</center>
291294
</footer>
292295
</body>

echoclient.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (c) 2016-present Cloud <[email protected]>
2+
//
3+
// This program is free software; you can redistribute it and/or
4+
// modify it under the terms of version 3 of the GNU General Public
5+
// License as published by the Free Software Foundation.
6+
//
7+
// This program is distributed in the hope that it will be useful, but
8+
// WITHOUT ANY WARRANTY; without even the implied warranty of
9+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10+
// General Public License for more details.
11+
//
12+
// You should have received a copy of the GNU General Public License
13+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
14+
15+
package brook
16+
17+
import (
18+
"fmt"
19+
"net"
20+
)
21+
22+
func EchoClient(server string, times int) error {
23+
c, err := net.Dial("tcp", server)
24+
if err != nil {
25+
return err
26+
}
27+
defer c.Close()
28+
var b [1024 * 2]byte
29+
for i := 0; i < times; i++ {
30+
if _, err := c.Write([]byte(c.LocalAddr().String())); err != nil {
31+
return err
32+
}
33+
i, err := c.Read(b[:])
34+
if err != nil {
35+
return err
36+
}
37+
if c.LocalAddr().String() == string(b[:i]) {
38+
fmt.Printf("TCP: src:%s -> dst:%s\n", c.LocalAddr().String(), c.RemoteAddr().String())
39+
fmt.Printf("TCP: dst:%s <- src:%s\n", c.LocalAddr().String(), c.RemoteAddr().String())
40+
}
41+
if c.LocalAddr().String() != string(b[:i]) {
42+
fmt.Printf("TCP: src:%s -> dst:proxy -> src:proxy -> dst:%s\n", c.LocalAddr().String(), c.RemoteAddr().String())
43+
fmt.Printf("TCP: dst:%s <- src:proxy <- dst:%s <- src:%s\n", c.LocalAddr().String(), string(b[:i]), c.RemoteAddr().String())
44+
}
45+
}
46+
47+
raddr, err := net.ResolveUDPAddr("udp", server)
48+
if err != nil {
49+
return err
50+
}
51+
c1, err := net.ListenUDP("udp", nil)
52+
if err != nil {
53+
return err
54+
}
55+
defer c1.Close()
56+
for i := 0; i < times; i++ {
57+
if _, err := c1.WriteToUDP([]byte(c1.LocalAddr().String()), raddr); err != nil {
58+
return err
59+
}
60+
i, addr, err := c1.ReadFromUDP(b[:])
61+
if err != nil {
62+
return err
63+
}
64+
if c1.LocalAddr().String() == string(b[:i]) {
65+
fmt.Printf("UDP: src:%s -> dst:%s\n", c1.LocalAddr().String(), raddr.String())
66+
fmt.Printf("UDP: dst:%s <- src:%s\n", c1.LocalAddr().String(), addr.String())
67+
}
68+
if c1.LocalAddr().String() != string(b[:i]) {
69+
fmt.Printf("UDP: src:%s -> dst:proxy -> src:proxy -> dst:%s\n", c1.LocalAddr().String(), raddr.String())
70+
fmt.Printf("UDP: dst:%s <- src:proxy <- dst:%s <- src:%s\n", c1.LocalAddr().String(), string(b[:i]), addr.String())
71+
}
72+
}
73+
return nil
74+
}

0 commit comments

Comments
 (0)