golang实现socket5代理服务器

socket5-server

介绍

socket5代理服务端、用转发网络请求。端口号为58888

package main

import (
	"flag"
	"fmt"
	"github.com/armon/go-socks5"
	"log"
)

func main() {
	var port int
	flag.IntVar(&port, "port", 58888, "Port for the proxy server")
	flag.Parse()

	// 创建 SOCKS5 服务器实例
	conf := &socks5.Config{}
	server, err := socks5.New(conf)
	if err != nil {
		log.Fatalf("Failed to create SOCKS5 server: %v", err)
	}

	// 监听并处理请求
	addr := fmt.Sprintf(":%d", port)
	log.Printf("SOCKS5 proxy server started on port %d\n", port)
	if err := server.ListenAndServe("tcp", addr); err != nil {
		log.Fatalf("Failed to start SOCKS5 server: %v", err)
	}
}
打包 进入源码目录
windows
 env GOOS=windows GOARCH=amd64 go build -o socket-server.exe

后台启动 - 编下以下脚本 保存为 vbs文件、点击即可

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "cmd /c socket-server.exe", 0
Linux
 env GOOS=linux GOARCH=amd64 go build -o socket-server-linux

后台通过nohup方式启动

 nohup ./socket-server-linux > /dev/null 2>&1  
Mac
 env GOOS=darwin GOARCH=amd64 go build -o socket-server-mac

后台通过nohup方式启动

 nohup ./socket-server-mac > /dev/null 2>&1  

你可能感兴趣的:(golang,golang,开发语言,后端)