forked from Juniper/go-netconf
/
telnet_example.go
43 lines (34 loc) · 946 Bytes
/
telnet_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
package main
import (
"flag"
"fmt"
"github.com/Juniper/go-netconf/netconf"
"github.com/Juniper/go-netconf/netconf/jnpr"
"os"
)
func main() {
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.DialTelnet(flag.Arg(0), *username, *password, &jnpr.JnprIOProc{})
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([]byte("<rpc><get-config><source><running/></source></get-config></rpc>"))
reply, err := s.ExecRPC(netconf.RPCGetConfig("running"))
if err != nil {
panic(err)
}
fmt.Printf("Reply: %+v", reply)
}