-
Notifications
You must be signed in to change notification settings - Fork 0
/
cisco.go
60 lines (47 loc) · 1.03 KB
/
cisco.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
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"fmt"
"log"
"os"
"strconv"
"golang.org/x/crypto/ssh"
)
func main() {
vlan := 68
user := "a++++++++++a"
pass := "6++++++++++9"
targethost := "xx.xx.xx.xx:2525"
//targethost := "ios-xe-mgmt.cisco.com:8181"
config := &ssh.ClientConfig{
User: user,
Auth: []ssh.AuthMethod{ssh.Password(pass)},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}
conn, err := ssh.Dial("tcp", targethost, config)
if err != nil {
log.Fatal("Failed to dial: ", err)
}
sess, err := conn.NewSession()
if err != nil {
log.Fatal("Failed to create session: ", err)
}
stdin, _ := sess.StdinPipe()
sess.Stdout = os.Stdout
sess.Stderr = os.Stderr
sess.Shell()
cmds := []string{
"conf t",
"int g1/0/7",
"switchport access vlan " + strconv.Itoa(vlan),
"shut",
"no shut",
"exit",
}
for _, cmd := range cmds {
fmt.Fprintf(stdin, "%s\n", cmd)
}
fmt.Fprintf(stdin, "exit\n")
fmt.Fprintf(stdin, "exit\n")
sess.Wait()
sess.Close()
}