You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
star/socks5/cmd.go

49 lines
1.2 KiB
Go

9 months ago
package socks5
import (
"b612.me/starlog"
"github.com/spf13/cobra"
"github.com/things-go/go-socks5"
"log"
"os"
)
var username, password string
var listen string
func init() {
Cmd.Flags().StringVarP(&username, "username", "u", "", "用户名")
Cmd.Flags().StringVarP(&password, "password", "p", "", "密码")
Cmd.Flags().StringVarP(&listen, "listen", "l", ":8000", "监听地址")
}
var Cmd = &cobra.Command{
Use: "socks5",
Short: "socks5代理",
Long: "socks5代理",
Run: func(cmd *cobra.Command, args []string) {
run()
},
}
func run() {
// Create a SOCKS5 server
var opt []socks5.Option
opt = append(opt, socks5.WithLogger(socks5.NewLogger(log.New(os.Stdout, "socks5: ", log.LstdFlags))))
if username != "" && password != "" {
opt = append(opt, socks5.WithAuthMethods([]socks5.Authenticator{
socks5.UserPassAuthenticator{Credentials: socks5.StaticCredentials{username: password}},
}))
}
server := socks5.NewServer(
opt...,
)
starlog.Infof("socks5 server listen on %s", listen)
// Create SOCKS5 proxy on localhost port 8000
if err := server.ListenAndServe("tcp", listen); err != nil {
starlog.Errorln("socks5 server error:", err)
os.Exit(1)
}
}