forked from Juniper/go-netconf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh_example.go
48 lines (37 loc) · 1.01 KB
/
ssh_example.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
41
42
43
44
45
46
47
48
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/Juniper/go-netconf/netconf"
)
func main() {
log := log.New(os.Stderr, "", log.LstdFlags)
netconf.SetLog(netconf.NewStdLog(log, netconf.LogDebug))
username := flag.String("username", "", "User to login with")
password := flag.String("password", "", "Password to login with")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [flags] targets...\n", os.Args[0])
flag.PrintDefaults()
os.Exit(2)
}
flag.Parse()
if flag.NArg() == 0 {
flag.Usage()
}
s, err := netconf.DialSSH(flag.Arg(0),
netconf.SSHConfigPassword(*username, *password))
if err != nil {
panic(err)
}
defer s.Close()
fmt.Printf("Server Capabilities: '%+v'\n", s.ServerCapabilities)
fmt.Printf("Session Id: %d\n\n", s.SessionID)
//reply, err := s.Exec(netconf.RawMethod("<rpc><get-config><source><running/></source></get-config></rpc>"))
reply, err := s.Exec(netconf.MethodGetConfig("running"))
if err != nil {
panic(err)
}
fmt.Printf("Reply: %+v", reply)
}