-
-
Save tumdum/afc52f43c257e655f0071701740b8f60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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