-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathssh-show_int_status.py
executable file
·75 lines (54 loc) · 1.94 KB
/
ssh-show_int_status.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
#####Original script taken from https://pynet.twb-tech.com/
######Written by:
######Kirk Byers
######CCIE #6243
######Twitter: @kirkbyers
######https://pynet.twb-tech.com/
######
######Garry Baker @networkbaker
######Made addtions as needed want to thank Kirk Byers for base script
######additions started 24JUNE2014
import paramiko
import time
def disable_paging(remote_conn):
'''Disable paging on a Cisco router'''
remote_conn.send("terminal length 0\n")
time.sleep(1)
# Clear the buffer on the screen
output = remote_conn.recv(1000)
return output
if __name__ == '__main__':
# VARIABLES THAT NEED CHANGED
#ip = '192.168.100.6'
#username = 'user'
#password = 'pass'
##addedd 14JUNE2014 interactive input for ip,user,password
##--Changed input to raw_input so no more ''
ip = raw_input("Enter IP address:'1.1.1.1' ")
username = raw_input("Enter username:'user' ")
password = raw_input("Enter password:'pass' ")
# Create instance of SSHClient object
remote_conn_pre = paramiko.SSHClient()
# Automatically add untrusted hosts (make sure okay for security policy in your environment)
remote_conn_pre.set_missing_host_key_policy(
paramiko.AutoAddPolicy())
# initiate SSH connection
remote_conn_pre.connect(ip, username=username, password=password)
print "SSH connection established to %s" % ip
# Use invoke_shell to establish an 'interactive session'
remote_conn = remote_conn_pre.invoke_shell()
print "Interactive SSH session established"
# Strip the initial router prompt
output = remote_conn.recv(1000)
# See what we have
print output
# Turn off paging
disable_paging(remote_conn)
# Now let's try to send the router a command
remote_conn.send("\n")
remote_conn.send("show int status\n")
# Wait for the command to complete
time.sleep(2)
output = remote_conn.recv(5000)
print output