本文整理汇总了Golang中golang.org/x/crypto/ssh.Client.DialTCP方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.DialTCP方法的具体用法?Golang Client.DialTCP怎么用?Golang Client.DialTCP使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/crypto/ssh.Client
的用法示例。
在下文中一共展示了Client.DialTCP方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: tunnelConnectionToPortUsingClient
func tunnelConnectionToPortUsingClient(localConn net.Conn, rport int, client *ssh.Client) {
addr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:"+strconv.Itoa(rport))
if err != nil {
panic(err)
}
remoteConn, err := client.DialTCP("tcp", nil, addr)
if err != nil {
panic(err)
}
wg := sync.WaitGroup{}
wg.Add(2)
copyConn := func(writer, reader net.Conn) {
defer wg.Done()
CopyAndMeasureThroughput(writer, reader)
}
go copyConn(localConn, remoteConn)
go copyConn(remoteConn, localConn)
go func() {
wg.Wait()
localConn.Close()
remoteConn.Close()
}()
}
示例2: NewTunnelledSSHClient
func NewTunnelledSSHClient(user, tunaddr, tgtaddr string, checker *HostKeyChecker, agentForwarding bool, timeout time.Duration) (*SSHForwardingClient, error) {
clientConfig, err := sshClientConfig(user, checker)
if err != nil {
return nil, err
}
tunaddr = maybeAddDefaultPort(tunaddr)
tgtaddr = maybeAddDefaultPort(tgtaddr)
var tunnelClient *gossh.Client
dialFunc := func(echan chan error) {
var err error
tunnelClient, err = gossh.Dial("tcp", tunaddr, clientConfig)
echan <- err
}
err = timeoutSSHDial(dialFunc, timeout)
if err != nil {
return nil, err
}
var targetConn net.Conn
dialFunc = func(echan chan error) {
tgtTCPAddr, err := net.ResolveTCPAddr("tcp", tgtaddr)
if err != nil {
echan <- err
return
}
targetConn, err = tunnelClient.DialTCP("tcp", nil, tgtTCPAddr)
echan <- err
}
err = timeoutSSHDial(dialFunc, timeout)
if err != nil {
return nil, err
}
c, chans, reqs, err := gossh.NewClientConn(targetConn, tgtaddr, clientConfig)
if err != nil {
return nil, err
}
return newSSHForwardingClient(gossh.NewClient(c, chans, reqs), agentForwarding)
}