Skip to content

Commit

Permalink
v20230101
Browse files Browse the repository at this point in the history
  • Loading branch information
txthinking committed Jan 1, 2023
1 parent 54ec07a commit bab614d
Show file tree
Hide file tree
Showing 9 changed files with 378 additions and 44 deletions.
89 changes: 82 additions & 7 deletions cli/brook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var debugAddress string
func main() {
app := cli.NewApp()
app.Name = "Brook"
app.Version = "20221212"
app.Version = "20230101"
app.Usage = "A cross-platform network tool designed for developers"
app.Authors = []*cli.Author{
{
Expand Down Expand Up @@ -221,7 +221,7 @@ func main() {
},
&cli.StringFlag{
Name: "http",
Usage: "Where to listen for HTTP connections",
Usage: "Where to listen for HTTP proxy connections",
},
&cli.IntFlag{
Name: "tcpTimeout",
Expand Down Expand Up @@ -443,7 +443,7 @@ func main() {
},
&cli.StringFlag{
Name: "http",
Usage: "Where to listen for HTTP connections",
Usage: "Where to listen for HTTP proxy connections",
},
&cli.IntFlag{
Name: "tcpTimeout",
Expand Down Expand Up @@ -712,7 +712,7 @@ func main() {
},
&cli.StringFlag{
Name: "http",
Usage: "Where to listen for HTTP connections",
Usage: "Where to listen for HTTP proxy connections",
},
&cli.IntFlag{
Name: "tcpTimeout",
Expand Down Expand Up @@ -1509,7 +1509,7 @@ func main() {
},
&cli.StringFlag{
Name: "http",
Usage: "Where to listen for HTTP connections",
Usage: "Where to listen for HTTP proxy connections",
},
&cli.IntFlag{
Name: "tcpTimeout",
Expand Down Expand Up @@ -2090,7 +2090,12 @@ func main() {
var cmd *exec.Cmd
var err error
go func() {
cmd = exec.Command("brook", "connect", "--link", c.String("link"), "--socks5", c.String("socks5"))
var s string
s, err = os.Executable()
if err != nil {
return
}
cmd = exec.Command(s, "connect", "--link", c.String("link"), "--socks5", c.String("socks5"))
b, _ := cmd.CombinedOutput()
err = errors.New(string(b))
}()
Expand All @@ -2103,6 +2108,76 @@ func main() {
return err1
},
},
&cli.Command{
Name: "echoserver",
Usage: "Echo server, echo UDP and TCP address of routes",
BashComplete: func(c *cli.Context) {
l := c.Command.VisibleFlags()
for _, v := range l {
fmt.Println("--" + v.Names()[0])
}
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "listen",
Aliases: []string{"l"},
Usage: "Listen address, like: ':7777'",
},
},
Action: func(c *cli.Context) error {
if c.String("listen") == "" {
return cli.ShowSubcommandHelp(c)
}
s, err := brook.NewEchoServer(c.String("listen"))
if err != nil {
return err
}
g := runnergroup.New()
g.Add(&runnergroup.Runner{
Start: func() error {
return s.ListenAndServe()
},
Stop: func() error {
return s.Shutdown()
},
})
go func() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
<-sigs
g.Done()
}()
return g.Wait()
},
},
&cli.Command{
Name: "echoclient",
Usage: "Connect to echoserver, echo UDP and TCP address of routes",
BashComplete: func(c *cli.Context) {
l := c.Command.VisibleFlags()
for _, v := range l {
fmt.Println("--" + v.Names()[0])
}
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "server",
Aliases: []string{"s"},
Usage: "Echo server address, such as 1.2.3.4:7777",
},
&cli.IntFlag{
Name: "times",
Value: 1,
Usage: "Times of interactions",
},
},
Action: func(c *cli.Context) error {
if c.String("server") == "" {
return cli.ShowSubcommandHelp(c)
}
return brook.EchoClient(c.String("server"), c.Int("times"))
},
},
&cli.Command{
Name: "completion",
Usage: "Generate shell completions",
Expand Down Expand Up @@ -2188,7 +2263,7 @@ complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete brook
},
},
&cli.Command{
Name: "markdown",
Name: "mdpage",
Usage: "Generate markdown page",
BashComplete: func(c *cli.Context) {
l := c.Command.VisibleFlags()
Expand Down
8 changes: 6 additions & 2 deletions docs/example-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ brook dnsserveroverbrook ... --listen 127.0.0.1:53
**无需操作 iptables!**

```
opkg install ca-certificates openssl-util ca-bundle coreutils-nohup iptables-mod-tproxy
opkg update
opkg install ca-certificates openssl-util ca-bundle coreutils-nohup iptables-mod-tproxy iptables-mod-socket
```

```
Expand Down Expand Up @@ -310,7 +311,10 @@ brook tproxy --link 'brook://...' --dnsListen :53

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

> **依赖: ca-certificates openssl-util ca-bundle coreutils-nohup iptables-mod-tproxy**
```
opkg update
opkg install ca-certificates openssl-util ca-bundle coreutils-nohup iptables-mod-tproxy iptables-mod-socket
```

**无需操作 iptables!**

Expand Down
8 changes: 6 additions & 2 deletions docs/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ Rule
**No need to manipulate iptables!**

```
opkg install ca-certificates openssl-util ca-bundle coreutils-nohup iptables-mod-tproxy
opkg update
opkg install ca-certificates openssl-util ca-bundle coreutils-nohup iptables iptables-mod-tproxy iptables-mod-socket
```

```
Expand Down Expand Up @@ -310,7 +311,10 @@ brook tproxy --link 'brook://...' --dnsListen :53

### GUI for official OpenWrt

> **Dependencies: ca-certificates openssl-util ca-bundle coreutils-nohup iptables-mod-tproxy**
```
opkg update
opkg install ca-certificates openssl-util ca-bundle coreutils-nohup iptables iptables-mod-tproxy iptables-mod-socket
```

**No need to manipulate iptables!**

Expand Down
Binary file added docs/images/linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 12 additions & 9 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ <h6><a href="https://github.com/txthinking/tun2brook" target="_blank">tun2brook<
<hr />
<div>
<h6>
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>
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>
</h6>
</div>
<pre><code>pacman -S brook</code></pre>
Expand Down Expand Up @@ -217,16 +217,19 @@ <h6>
<div style="font-size: 12px">Windows EXE</div>
</div></a
>
<a href="https://github.com/txthinking/brook/releases" target="_blank"
<div style="display:flex;flex-direction:column;align-items:center;">
<a href="https://github.com/txthinking/brook/releases/latest/download/Brook.bin" target="_blank"
><div style="display: flex; flex-direction: column; align-items: center; padding: 30px">
<img src="./images/openwrt.png" style="width: 50px; height: 50px" />
<div style="font-size: 12px">OpenWrt IPK</div>
<img src="./images/linux.png" style="width: 50px; height: 50px" />
<div style="font-size: 12px">Linux GUI</div>
</div></a
>
<a href="https://chrome.google.com/webstore/detail/hnpgnjkeaobghpjjhaiemlahikgmnghb" target="_blank"
<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>
</div>
<a href="https://github.com/txthinking/brook/blob/master/docs/example.md#gui-for-official-openwrt" target="_blank"
><div style="display: flex; flex-direction: column; align-items: center; padding: 30px">
<img src="./images/sc.png" style="width: 50px; height: 50px" />
<div style="font-size: 12px">Chrome EXT</div>
<img src="./images/openwrt.png" style="width: 50px; height: 50px" />
<div style="font-size: 12px">OpenWrt IPK</div>
</div></a
>
</div>
Expand Down Expand Up @@ -284,9 +287,9 @@ <h6>{{ zh ? '移除某个开机命令' : 'Remove one added command' }}</h6>
<article v-html="p7c"></article>
</div>
</main>
<footer class="container" style="font-size: 14px; color: #919191">
<footer class="container" style="font-size: 14px">
<center>
<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>
<p style="font-size: 14px"><a style="font-size: 14px" href="https://github.com/txthinking/brook/tree/master/protocol">Undetectable Protocol</a></p>
</center>
</footer>
</body>
Expand Down
74 changes: 74 additions & 0 deletions echoclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) 2016-present Cloud <cloud@txthinking.com>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 3 of the GNU General Public
// License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package brook

import (
"fmt"
"net"
)

func EchoClient(server string, times int) error {
c, err := net.Dial("tcp", server)
if err != nil {
return err
}
defer c.Close()
var b [1024 * 2]byte
for i := 0; i < times; i++ {
if _, err := c.Write([]byte(c.LocalAddr().String())); err != nil {
return err
}
i, err := c.Read(b[:])
if err != nil {
return err
}
if c.LocalAddr().String() == string(b[:i]) {
fmt.Printf("TCP: src:%s -> dst:%s\n", c.LocalAddr().String(), c.RemoteAddr().String())
fmt.Printf("TCP: dst:%s <- src:%s\n", c.LocalAddr().String(), c.RemoteAddr().String())
}
if c.LocalAddr().String() != string(b[:i]) {
fmt.Printf("TCP: src:%s -> dst:proxy -> src:proxy -> dst:%s\n", c.LocalAddr().String(), c.RemoteAddr().String())
fmt.Printf("TCP: dst:%s <- src:proxy <- dst:%s <- src:%s\n", c.LocalAddr().String(), string(b[:i]), c.RemoteAddr().String())
}
}

raddr, err := net.ResolveUDPAddr("udp", server)
if err != nil {
return err
}
c1, err := net.ListenUDP("udp", nil)
if err != nil {
return err
}
defer c1.Close()
for i := 0; i < times; i++ {
if _, err := c1.WriteToUDP([]byte(c1.LocalAddr().String()), raddr); err != nil {
return err
}
i, addr, err := c1.ReadFromUDP(b[:])
if err != nil {
return err
}
if c1.LocalAddr().String() == string(b[:i]) {
fmt.Printf("UDP: src:%s -> dst:%s\n", c1.LocalAddr().String(), raddr.String())
fmt.Printf("UDP: dst:%s <- src:%s\n", c1.LocalAddr().String(), addr.String())
}
if c1.LocalAddr().String() != string(b[:i]) {
fmt.Printf("UDP: src:%s -> dst:proxy -> src:proxy -> dst:%s\n", c1.LocalAddr().String(), raddr.String())
fmt.Printf("UDP: dst:%s <- src:proxy <- dst:%s <- src:%s\n", c1.LocalAddr().String(), string(b[:i]), addr.String())
}
}
return nil
}
Loading

0 comments on commit bab614d

Please sign in to comment.