socks5-server/server.go

35 lines
639 B
Go
Raw Normal View History

2016-12-20 13:09:34 +03:00
package main
import (
2018-04-15 21:08:32 +03:00
"fmt"
2016-12-20 13:09:34 +03:00
"log"
2018-04-15 21:08:32 +03:00
"os"
"github.com/armon/go-socks5"
2016-12-20 13:09:34 +03:00
)
func main() {
2018-04-15 21:08:32 +03:00
2016-12-20 13:09:34 +03:00
conf := &socks5.Config{
2018-04-15 21:08:32 +03:00
Logger: log.New(os.Stdout, "", log.LstdFlags),
2016-12-20 13:09:34 +03:00
}
2018-04-15 21:08:32 +03:00
if os.Getenv("PROXY_USER")+os.Getenv("PROXY_PASSWORD") != "" {
creds := socks5.StaticCredentials{
os.Getenv("PROXY_USER"): os.Getenv("PROXY_PASSWORD"),
}
cator := socks5.UserPassAuthenticator{Credentials: creds}
conf.AuthMethods = []socks5.Authenticator{cator}
}
2016-12-20 13:09:34 +03:00
server, err := socks5.New(conf)
if err != nil {
2018-04-15 21:08:32 +03:00
log.Fatal(err)
2016-12-20 13:09:34 +03:00
}
2018-04-15 21:08:32 +03:00
fmt.Println("Start listening ...")
if err := server.ListenAndServe("tcp", ":1080"); err != nil {
log.Fatal(err)
2016-12-20 13:09:34 +03:00
}
2018-04-15 21:08:32 +03:00
}