1.项目地址
2.安装go环境
3.go换源
go env -w GO111MODULE=auto go env -w GOPROXY=https://goproxy.cn,direct
4.安装依赖、socks5包
go get -u github.com/oov/socks5
5.运行以下代码
go run main.go
package main import ( "github.com/oov/socks5" "log" ) func main() { srv := socks5.New() srv.AuthUsernamePasswordCallback = func(c *socks5.Conn, username, password []byte) error { /*账号密码验证*/ user := string(username) passwd := string(password) if !((user == "guest" && passwd == "test1234") || (user == "root" && passwd == "test1234")) { return socks5.ErrAuthenticationFailed } log.Printf("Welcome %v!", user) c.Data = user return nil } /*代理黑名单*/ srv.HandleConnectFunc(func(c *socks5.Conn, host string) (newHost string, err error) { if host == "example.com:80" { return host, socks5.ErrConnectionNotAllowedByRuleset } if user, ok := c.Data.(string); ok { log.Printf("%v connecting to %v", user, host) } return host, nil }) srv.HandleCloseFunc(func(c *socks5.Conn) { if user, ok := c.Data.(string); ok { log.Printf("Goodbye %v!", user) } }) /*监听8070端口*/ srv.ListenAndServe(":8070") }
6.测试代理
7.编译成独立的可执行程序
go build main.go