I wanted to know if it is possible to listen to a local port ex: 1080 socks5, and all connections on that port be made a proxy to use an external host:port socks5
func main() {
l, err := net.Listen("tcp", "127.0.0.1:1080")
if err != nil {
fmt.Print(err)
}
defer l.Close()
for {
conn, err := l.Accept()
if err != nil {
fmt.Print(err)
}
go handle(conn)
}
}
func handle(conn net.Conn) {
defer conn.Close()
dialect, err := proxy.SOCKS5("tcp", "externalhost:externalport", nil, proxy.Direct)
newConn, err := dialect.Dial("tcp", "targethost:targetport")
if err != nil {
log.Printf("Connection error: %s", err.Error())
}
go func() {
_, err = io.Copy(newConn, conn)
if err != nil {
log.Printf("Connection error: %s", err.Error())
}
}()
_, err = io.Copy(conn, newConn)
if err != nil {
log.Printf("Connection error: %s", err.Error())
}
}
func handle(conn net.Conn) {
defer conn.Close()
}
I would need to get the destination addres and validate if the connection is socks5 and then perform the proxy with the external ip and pass it in the dialect.dial