Skip to content

Instantly share code, notes, and snippets.

@tumdum

tumdum/main.go Secret

Created July 10, 2021 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tumdum/afc52f43c257e655f0071701740b8f60 to your computer and use it in GitHub Desktop.
Save tumdum/afc52f43c257e655f0071701740b8f60 to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"io"
"net"
)
func proxy(from string, to string) error {
listener, err := net.Listen("tcp", from)
if err != nil {
return err
}
for {
fromConn, err := listener.Accept()
if err != nil {
return err
}
toConn, err := net.Dial("tcp", to)
if err != nil {
return err
}
go io.Copy(toConn, fromConn)
go io.Copy(fromConn, toConn)
}
}
func main() {
from := flag.String("from", "", "address from which we will accept connections")
to := flag.String("to", "", "address to which we will forward traffic")
flag.Parse()
proxy(*from, *to)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment