Skip to content

Instantly share code, notes, and snippets.

@nl5887
Last active July 2, 2018 12:20
Show Gist options
  • Select an option

  • Save nl5887/c913043f7fbbef221a2445fefb865eca to your computer and use it in GitHub Desktop.

Select an option

Save nl5887/c913043f7fbbef221a2445fefb865eca to your computer and use it in GitHub Desktop.
Connects two outgoing connections
package main
import (
"fmt"
"io"
"net"
"os"
)
func main() {
if len(os.Args) != 3 {
fmt.Println("proxy src dst")
os.Exit(1)
}
fmt.Println("Connecting to ", os.Args[1])
conn2, err := net.Dial("tcp", os.Args[1])
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Connected to ", os.Args[1])
fmt.Println("Connecting to ", os.Args[2])
conn, err := net.Dial("tcp", os.Args[2])
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Connected to ", os.Args[2])
go io.Copy(conn2, conn)
io.Copy(conn, io.TeeReader(conn2, os.Stdout))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment