This commit is contained in:
netbyte 2021-12-15 17:16:29 +08:00
parent d986163492
commit 8245e4a8ce
5 changed files with 13 additions and 1 deletions

View File

@ -25,6 +25,8 @@ Usage of ./vtun:
protocol ws/wss/udp (default "wss")
-s string
server address (default ":3001")
-d string
dns address (default "8.8.8.8:53")
-P enable pporf server on :6060
-S server mode
-g client global mode

View File

@ -13,6 +13,7 @@ type Config struct {
CIDR string
Key string
Protocol string
DNS string
ServerMode bool
GlobalMode bool
Obfuscate bool

View File

@ -40,6 +40,13 @@ func GetAddr(b []byte) (srcAddr string, dstAddr string) {
}
func ConnectServer(config config.Config) net.Conn {
net.DefaultResolver = &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, _ string) (net.Conn, error) {
var dialer net.Dialer
return dialer.DialContext(ctx, network, config.DNS)
},
}
scheme := "ws"
if config.Protocol == "wss" {
scheme = "wss"

View File

@ -17,6 +17,7 @@ func main() {
flag.StringVar(&config.ServerAddr, "s", ":3001", "server address")
flag.StringVar(&config.Key, "k", "6w9z$C&F)J@NcRfWjXn3r4u7x!A%D*G-", "key")
flag.StringVar(&config.Protocol, "p", "wss", "protocol ws/wss/udp")
flag.StringVar(&config.DNS, "d", "8.8.8.8:53", "dns address")
flag.BoolVar(&config.ServerMode, "S", false, "server mode")
flag.BoolVar(&config.GlobalMode, "g", false, "client global mode")
flag.BoolVar(&config.Obfuscate, "o", false, "enable data obfuscation")

View File

@ -40,8 +40,8 @@ func configTun(config config.Config, iface *water.Interface) {
if physicalIface != "" && serverIP != "" {
execCmd("/sbin/ip", "route", "add", "0.0.0.0/1", "dev", iface.Name())
execCmd("/sbin/ip", "route", "add", "128.0.0.0/1", "dev", iface.Name())
execCmd("/sbin/ip", "route", "delete", strings.Join([]string{serverIP, "32"}, "/"), "via", gateway, "dev", physicalIface)
execCmd("/sbin/ip", "route", "add", strings.Join([]string{serverIP, "32"}, "/"), "via", gateway, "dev", physicalIface)
execCmd("/sbin/ip", "route", "add", strings.Join([]string{strings.Split(config.DNS, ":")[0], "32"}, "/"), "via", gateway, "dev", physicalIface)
}
}
@ -54,6 +54,7 @@ func configTun(config config.Config, iface *water.Interface) {
serverIP := netutil.LookupIP(strings.Split(config.ServerAddr, ":")[0])
if physicalIface != "" && serverIP != "" {
execCmd("route", "add", serverIP, localGateway)
execCmd("route", "add", strings.Split(config.DNS, ":")[0], localGateway)
execCmd("route", "add", "0.0.0.0/1", "-interface", iface.Name())
execCmd("route", "add", "128.0.0.0/1", "-interface", iface.Name())
execCmd("route", "add", "default", gateway.String())