-
Notifications
You must be signed in to change notification settings - Fork 3
/
cisco-ssh.py
52 lines (41 loc) · 1.01 KB
/
cisco-ssh.py
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
#!/usr/bin/python
# A script to ssh into a cisco device, set the terminal length
# such that paging is turned off, then run commands.
# the results go into 'resp', then are displayed.
# Tweak to your hearts content!
import paramiko
import cmd
import time
import sys
buff = ''
resp = ''
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('1.1.1.1', username='admin', password='password')
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
chan = ssh.invoke_shell()
# first we enable!
chan.send('en\n')
time.sleep(1)
resp = chan.recv(9999)
#print resp
# enablepassword!
chan.send('enablepassword\n')
time.sleep(1)
resp = chan.recv(9999)
#print resp
# get into config mode
chan.send('conf t\n')
time.sleep(1)
resp = chan.recv(9999)
#print resp
# turn off paging
chan.send('terminal pager 0\n')
time.sleep(1)
resp = chan.recv(9999)
#print resp
# Display how many users are connected to the IPSEC vpn
chan.send('sh cry isa sa\n')
time.sleep(1)
resp = chan.recv(9999)
print resp