forked from Juniper/go-netconf
/
ssh2.go
40 lines (31 loc) · 807 Bytes
/
ssh2.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Go NETCONF Client - Example
//
// Copyright (c) 2013-2018, Juniper Networks, Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"log"
"github.com/adkhadilkar/go-netconf/netconf"
"golang.org/x/crypto/ssh"
)
func main() {
sshConfig := &ssh.ClientConfig{
User: "myuser",
Auth: []ssh.AuthMethod{ssh.Password("mypass")},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}
s, err := netconf.DialSSH("1.1.1.1", sshConfig)
if err != nil {
log.Fatal(err)
}
defer s.Close()
fmt.Println(s.ServerCapabilities)
fmt.Println(s.SessionID)
reply, err := s.Exec(netconf.MethodGetConfig("running"))
if err != nil {
panic(err)
}
fmt.Printf("Reply: %+v", reply)
}