1 Star 0 Fork 23

Alex314/shadowtunnel

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 2.54 KB
一键复制 编辑 原始数据 按行查看 历史
snail007 提交于 2018-06-19 14:18 . Create main.go
package main
import (
"flag"
"fmt"
"log"
"net"
"os"
"strings"
"time"
encryptconn "bitbucket.org/goproxy/proxy/net/common/transport/encrypt"
clienttransport "bitbucket.org/goproxy/proxy/net/transport/client"
srvtransport "bitbucket.org/goproxy/proxy/net/transport/server"
utils "bitbucket.org/goproxy/proxy/utils"
)
const (
VERSION = "1.0"
)
var (
listenAddr string
forwardAddr string
timeout int
compress bool
method string
password string
listen srvtransport.ServerChannel
l = log.New(os.Stderr, "", log.LstdFlags)
err error
inboundEncrypt bool
outboundEncrypt bool
version bool
)
func main() {
flag.StringVar(&listenAddr, "l", ":50000", "local listen address, such as : 0.0.0.0:33000")
flag.StringVar(&method, "m", "aes-192-cfb", "method of encrypt/decrypt, these below are supported :\n"+strings.Join(encryptconn.GetCipherMethods(), ","))
flag.StringVar(&password, "p", "shadowtunnel", "password of encrypt/decrypt")
flag.StringVar(&forwardAddr, "f", "", "forward address,such as : 127.0.0.1:8080")
flag.IntVar(&timeout, "t", 3, "connection timeout seconds")
flag.BoolVar(&compress, "c", true, "compress traffic")
flag.BoolVar(&inboundEncrypt, "e", false, "inbound connection is encrypted")
flag.BoolVar(&outboundEncrypt, "E", false, "outbound connection is encrypted")
flag.BoolVar(&version, "v", false, "show version")
flag.Parse()
if version {
fmt.Println(VERSION)
return
}
if forwardAddr == "" || listenAddr == "" {
flag.Usage()
return
}
listen = srvtransport.NewServerChannelHost(listenAddr, l)
if inboundEncrypt {
err = listen.ListenTCPS(method, password, compress, callback)
} else {
err = listen.ListenTCP(callback)
}
if err != nil {
l.Fatal(err)
}
l.Printf("shadowtunnel listen on : %s", (*listen.Listener).Addr())
select {}
}
func callback(conn net.Conn) {
defer func() {
if e := recover(); e != nil {
l.Printf("connection handler crashed :\n%s", err)
}
}()
remoteAddr := conn.RemoteAddr()
var outconn net.Conn
if outboundEncrypt {
outconn, err = clienttransport.TCPSConnectHost(forwardAddr, method, password, compress, timeout*1000)
} else {
outconn, err = net.DialTimeout("tcp", forwardAddr, time.Duration(timeout)*time.Second)
}
if err != nil {
l.Printf("%s <--> %s, error: %s", remoteAddr, forwardAddr, err)
conn.Close()
return
}
utils.IoBind(conn, outconn, func(err interface{}) {
l.Printf("%s <--> %s released", remoteAddr, forwardAddr)
}, l)
l.Printf("%s <--> %s connected", remoteAddr, forwardAddr)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/fzwise/shadowtunnel.git
[email protected]:fzwise/shadowtunnel.git
fzwise
shadowtunnel
shadowtunnel
master

搜索帮助