-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (41 loc) · 1.2 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"log"
"net"
"os"
"github.com/things-go/go-socks5"
)
func main() {
if len(os.Args) < 5 {
log.Fatal("Usage: go run main.go <username> <password> <listening_address> <listening_port>")
}
username := os.Args[1]
password := os.Args[2]
listeningAddress := os.Args[3]
listeningPort := os.Args[4]
// Validate listening address
if ip := net.ParseIP(listeningAddress); ip == nil {
log.Fatalf("Invalid listening address: %s", listeningAddress)
}
// Validate listening port
if port, err := net.LookupPort("tcp", listeningPort); err != nil {
log.Fatalf("Invalid listening port: %s", listeningPort)
} else if port < 1 || port > 65535 {
log.Fatalf("Invalid listening port: %d", port)
}
cator := socks5.UserPassAuthenticator{
socks5.StaticCredentials{
username: password,
},
}
server := socks5.NewServer(
socks5.WithAuthMethods([]socks5.Authenticator{cator}),
socks5.WithLogger(socks5.NewLogger(log.New(os.Stdout, "socks5: ", log.LstdFlags))),
)
// Create SOCKS5 proxy on the specified address and port
listeningAddr := fmt.Sprintf("%s:%s", listeningAddress, listeningPort)
if err := server.ListenAndServe("tcp", listeningAddr); err != nil {
panic(err)
}
}