Skip to content

Instantly share code, notes, and snippets.

@nabeken
Last active August 29, 2015 14:20
Show Gist options
  • Save nabeken/59594bce8cafddfc9cf0 to your computer and use it in GitHub Desktop.
Save nabeken/59594bce8cafddfc9cf0 to your computer and use it in GitHub Desktop.
Proxy Protocol Checker
package main
import (
"flag"
"io"
"log"
"net"
"os"
"github.com/armon/go-proxyproto"
)
func cp(conn net.Conn) {
defer conn.Close()
if _, err := io.Copy(os.Stdout, conn); err != nil {
log.Print(err)
}
}
func main() {
useProxyProto := flag.Bool("proxy", false, "enable Proxy Protocol")
flag.Parse()
host := flag.Arg(0)
ln, err := net.Listen("tcp", host)
if err != nil {
log.Fatal(err)
}
if *useProxyProto {
ln = &proxyproto.Listener{ln}
}
for {
conn, err := ln.Accept()
if err != nil {
log.Print(err)
continue
}
remote := conn.RemoteAddr()
log.Printf("remote: %s", remote)
go cp(conn)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment