go.crypto/ssh: add support for remote tcpip forwarding
Add support for server (remote) forwarded tcpip channels. See RFC4254 Section 7.1 R=gustav.paul, jeff, agl, lieqiewang CC=golang-dev https://golang.org/cl/6038047
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"code.google.com/p/go.crypto/ssh/terminal"
|
||||
)
|
||||
@@ -120,3 +122,30 @@ func ExampleDial() {
|
||||
}
|
||||
fmt.Println(b.String())
|
||||
}
|
||||
|
||||
func ExampleClientConn_Listen() {
|
||||
config := &ClientConfig{
|
||||
User: "username",
|
||||
Auth: []ClientAuth{
|
||||
ClientAuthPassword(password("password")),
|
||||
},
|
||||
}
|
||||
// Dial your ssh server.
|
||||
conn, err := Dial("tcp", "localhost:22", config)
|
||||
if err != nil {
|
||||
log.Fatalf("unable to connect: %s", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
// Request the remote side to open port 8080 on all interfaces.
|
||||
l, err := conn.Listen("tcp", "0.0.0.0:8080")
|
||||
if err != nil {
|
||||
log.Fatalf("unable to register tcp forward: %v", err)
|
||||
}
|
||||
defer l.Close()
|
||||
|
||||
// Serve HTTP with your SSH server acting as a reverse proxy.
|
||||
http.Serve(l, http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
|
||||
fmt.Fprintf(resp, "Hello world!\n")
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user